Question: ( 5 ) Write a C program prog 5 . c that accepts a single command line argument, which is the name of a file
Write a C program prog c that accepts a single command line argument, which is the name of a file to be
processed. Your program should then:
Ensure that a single command line argument has been provided and exit with a descriptive error message
if the command line argument is omitted.
Open the file using fopen Exit with a descriptive error message if the file can't be opened.
Determine the exact size of the file in bytes.
Using malloc dynamically allocate space for a C string that is long enough to hold the entire contents
of the file.
Issue a single fread that reads the entire contents of the file into the string.
Close the file using fclose
Null terminate the string.
Tokenize the string, using the C standard library function strtok with whitespace spaces tabs
newlines and commas as delimiters.
Output each token, one per line.
Free the storage associated with the string.
Use the following command under Linux to compile your program:
$gcc Wall o prog progc
You should receive no warnings!
Could you please show the code
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
