Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you are to implement and test a C program that copies the content of a file to another file. You must

 

In this assignment, you are to implement and test a C program that copies the content of a file to another file. You must read the descriptions of the standard C functions open, close, read, write, perror, and exit(). Use program man to access the manual pages. Yes, they are on your computer. Your program shall be called copy, consist of one file, and compile without any warnings with the compiler options -Wall-Wextra-Wpedantic-Wno-unused-function. The program shall take zero or two command line options (CLOS). If the program has zero CLOs, it shall copy the standard output to the standard input: shell: copy < existing_file > new_file If the program has two CLOs, they shall be interpreted as the names of the existing input file and the output file: shell: copy existing_file new_file In the latter case, the program shall close the files before exiting. The program shall check the return value of any standard library function and report any error using the perror() function. The argument of the function is a reference to what caused the problem, not the problem itself. For example, if you cannot open file infile, you must call perror(infile), not perror("Cannot open file"). [Try it both ways and explain why.] The program shall report usage error (the wrong number of CLOS) by displaying a gentle error message and an instruction on how to call it correctly, e.g.: shell: copy existing_file Incorrect number of arguments. Usage: copy copy INFILE OUTFILE The program shall exit with an error exit code EXIT FAILURE if it encounters an error and with the success exit code EXIT SUCCESS otherwise. The program shall not assume that the files contain text; the files may be binary (images, videos). The program, therefore, shall use only the functions listed above. The program shall not assume that the files are small or medium-size. The program shall read the input file piecewise, in a loop, in fixed-size chunks (define the chunk size as a macro with the #define operator). Test the program using it both ways (with the CLOs and without them); with text files and binary files; with non-existent input file; with a previously existing output file; with a previously existing read-only output file (make it read-only before running the program). Submit the C file (no text files, no executable files).

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_2

Step: 3

blur-text-image_3

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

Computer Architecture A Quantitative Approach

Authors: John L. Hennessy, David A. Patterson

4th edition

123704901, 978-0123704900

More Books

Students also viewed these Algorithms questions

Question

Please answer the question in the screenshot below:

Answered: 1 week ago

Question

4. How does light reset the biological clock?

Answered: 1 week ago

Question

21. How does L-dopa relieve the symptoms of Parkinsons disease?

Answered: 1 week ago