Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a ‘C’ program that performs some functions of a file preprocessor. This pr

ID: 3670080 • Letter: W

Question

Write a ‘C’ program that performs some functions of a file preprocessor.

This program should accept a –f option that specifies a filename to contain the output of the program. If the –f option is not specified, the program should send the output to standard output.

You must use freopen(…) to create the stream for the program’s output if the output is going to standard output.

The program should accept zero or more arguments. If no arguments are specified, the program should get it’s input from standard input. If one or more arguments are specified, the program should get its input from the files whose names are specified as arguments. If arguments are specified, the program should send to standard error the name of each file followed by the date/time the file was modified in the format YYYY_MM_DD_HH_MM_SS and then a trailing newline. For example, if the file named “file1.txt” was last modified on February 4, 2016 at 5:30 p.m., the program should send to standard error the following string: “file1.txt 2015_02_04_17_30_00 ”

You must use getopt() to process the option and arguments.

Examples (assumes the program has been built as an executable named “preprocess”):

preprocess

Accepts input from standard input and sends processed output to standard output

preprocess –f outputfile.txt

Accepts input from standard input and sends processed output to a file called outputfile.txt

preprocess file1.txt file2.txt

Accepts input from file1.txt followed by file2.txt and sends the combined processed output to standard output. Also sends to standard error the name of each file and the last modified date/time as specified above.

preprocess –f outputfile.txt file1.txt file2.txt

Accepts input from file1.txt followed by file2.txt and sends the combined processed output to a file called outputfile.txt. Also sends to standard error the name of each file and the last modified date/time as specified above.

As the input is read, it is simply copied to the output, with two exceptions:

• If the string “#include” is found at the beginning of a line, it will be followed by a space then a filename in the form of ”. For example, you may see a line that begins with “#include ”. If the input contains that at the beginning of the line, output the contents of file3.txt rather than the “#include ”. The remainder of the line is ignored. If anything follows the on the line it is ignored and processing begins on the next line.

• Anytime the string is found in the input, replace with the number of seconds elapsed since February 4, 2016 5:30 p.m.

Explanation / Answer

/*

* File: newmain.c

* Author: HARE KRISHNA

*

* Created on 21 February, 2016, 8:06 AM

*/

#include <stdio.h>

#include <stdlib.h>

/*

*

*/

int main(int argc, char** argv) {

FILE *fp;

char filename;

char c;

prinntf("Enter file name");

scanf("%c",filename);

  

  

funny = fopen(filename, "r");

if (fp == NULL)

printf("File doesn't exist ");

else {

do {

c = getc(fp); /* get one character from the file*/

putchar(c); /* display it on the monitor*/

} while (c != EOF); /* repeat until EOF (end of file)*/

}

fclose(fp);

}

  

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote