Question: This assignment is an exercise in C programming, specifically in using the C library to do file input and to do some basic string processing.
This assignment is an exercise in C programming, specifically in using the C library to do file input and to do some basic string processing. It probably introduces you to at least one C library function that you have never used before. Knowing what library capability is available in any programming language's environment iskeyto using that programming language well, so here we learn a little about the C library!
Requirements
Write a plain C program that reads a plain text file and outputs the number of "words"andthe number of lines that the file contains. Your program must adhere to both the behavioral specification and the programming requirements below.
Behavioral Specification
The program must take either zero or one command line argument. If there is zero arguments then standard input stdin is used for input, otherwise the argument is the name of the input file to use. If more than one argument is given, your program must output both an error and a usage message, and then exit. If the argument given cannot be opened as a file for reading, your program must output an error message and then exit.
The program must output two decimal whole numbers separated by one tab character, and followed by one newline character. Nothing else. The first number is the number of "words" that the input contained, and the second is the number of lines. These numbers should match the count that the Unix command wc gives.
A word is a nonzero sequence of nonwhitespace characters followed by at least one whitespace character, or EOF. Multiple whitespace characters may be in between words. Whitespace characters are space tab t newline
and carriage return r Carriage returns generally do not occur in Unix text files, but may in Windows text files. A line is a sequence of nonnewline characters followed by a newline or EOF A line may be empty zero nonnewline characters it still counts as a line.
Your program must exit with a return value from main of zero if it successfully processed its input, or otherwise.
Programming Requirements
You must use the C library functionfgetsto read in one line at a time from input file orstdin You can assume that no line is longer than characters including the newline Since you must use fgets to read the file, it is best to usefopenandfcloseto open and close the file. You cannot open, and should not close,stdin
You must use the C library functionstrtokto identify words in the input. This function is meant to use repetitively in sequence on a data string. It's cool!
You must create a function named 'processLine that is called once for each line in the input; its job is to process the given input line. It can have whatever parameters and return value you deem necessary.
Your programmust nothave any global variables; you must use arguments and return values to communicate between functions.
Your program must have a file header comment, function header comments, and other comments as appropriate.
You must create a Makefile that compiles your program into an executable named hwwc
Your Makefile must use the flag Wall' when it invokes the Gnu C compiler, and your program must compile with zero warnings evident.
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
