Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I uploaded the sample please do it asap Use the program 7-6ErrorHandlingStderrExit.c on Canvas in Course Documents, Programs and Data File. When executing on the

I uploaded the sample please do it asap

Use the program 7-6ErrorHandlingStderrExit.c on Canvas in Course Documents, Programs and Data File. When executing on the command line only this program name, the program will accept keyboard input and display such until the user does control+break to exit the program.

The new code should within only this case situation

if (argc == 1){ /* no args; copy standard input */

Replace line #20 filecopy(stdin, stdout); with new code.

Open and read a text file 7NoInputFileResponse.txt that contains a response message There were no arguments on the command line to be read for file open. If file is empty, then use alternate message "22F Missing file 7-0NoInputFileResponse.txt" advance line.

Make the program output to the text log file a new line starting with formatted abbreviation for Weekday 12-hour clock time formatted as hour:minutes:seconds AM/PM date formatted as mm/dd/yyyy followed by the message "COMMAND LINE INPUT SUCCESSFUL". See example 7-8MiscFunctionsTime on Canvas.

Append that message to a file 7Error_Log_File.txt advance newline.

Remember to be using fprintf, using stderr, using return, using exit statements. Test for existence of 7NoInputFileResponse.txt file when not null print 7Error_Log_File.txt does exist however if null use, otherwise display such message using fprintf stderr and exit.

Upload your .c file your input message file and your text log file.

7-6ErrorHandlingStderrExit.c

#include #include /*needed for stderr and exit */ /* cat: concatenate files, version 2 */ /* filecopy: copy file ifp to file ofp */ void filecopy(FILE *ifp, FILE *ofp) /* pointer to input file, output file */ { int c; while ((c = getc(ifp)) != EOF) putc(c, ofp); } int main(int argc, char *argv[]) { FILE *fp; void filecopy(FILE *, FILE *); char *prog = argv[0]; /* this program exe name as source of an error */ if (argc == 1){ /* when no args on command line, copy keyboard to display, must ctrl_break or End to exit */ filecopy(stdin, stdout); /* stdin is the standard input keyboard , stdout is the standard output screen display */ } else while (--argc > 0) if (( fp = fopen(*++argv, "r")) == NULL) { /* pointer to next command line file */ fprintf(stderr, " ERROR the program %s can not open command line file %s ", prog, *argv); /*fprintf allows stderr message */ exit(1); /* determined by programmer return value for error type #1 */ } else { /*the contents of each command line file are printed in this block structure*/ filecopy(fp, stdout); fclose (fp); } /*The ferror() function tests for an error in reading from or writing to the given stream. If an error occurs, the error indicator for the stream remains set until you close stream, call the rewind() function, or call the clearerr() function. The ferror() function returns a nonzero value to indicate an error on the given stream. A return value of 0 means that no error has occurred. */ if(ferror(stdout)) { fprintf(stderr, "%s: error writing stdout ", prog); exit(2); /* determined by programmer return value for error type #2 */ } exit(0); /* determined by programmer return value for error type #0, success */ }

7-8MiscFunctionsTime

int main(void) { time_t t; time_t current_time; char* c_time_string; char buffer[SIZE]; time_t curtime; struct tm *loctime; /* Obtain current time. */ current_time = time(NULL); if (current_time == ((time_t)-1)) { (void) fprintf(stderr, "Failure to obtain the current time. "); exit(EXIT_FAILURE); } /* Convert to local time format. */ c_time_string = ctime(¤t_time); if (c_time_string == NULL) { (void) fprintf(stderr, "Failure to convert the current time. "); exit(EXIT_FAILURE); } /* Print to stdout. ctime() has already added a terminating newline character. */ (void) printf("Goodbye! "); printf("Current time is %s", c_time_string); exit(EXIT_SUCCESS); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions

Question

d. What language(s) did they speak?

Answered: 1 week ago