Write a program countfile.c that calculates and prints on screen the number of bytes or number of lines in a file. To print the number of lines in the file myfile.txt, the program is run from the...


Write a program countfile.c that calculates and prints on screen the number of bytesor number of lines in a file.

To print the number of lines in the file myfile.txt, the program is run from the command line with two arguments as follows


countfile.exe -l myfile.txt


or, to print the number of bytes in the file myfile.txt, it would be run as


countfile.exe -b myfile.txt



EXAMPLE:

Suppose the file myfile.txt contains the following


ali

veli

49

50


Then running

countfile.exe -l myfile.txt

would print 4 on the screen.


And running

countfile.exe -b myfile.txt

would print 15 on the screen.


If as a switch anything other than -l or -b is used, the program should give an error message and exit with code 1.

If the file is not found, then it should give a message saying no such file exists, and exit with code 2.

If everything runs correctly the program should return 0.



Jun 02, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here