Please read the
homework guidelines before you proceed.
Using only the features of C you have learned in so far write a C program that takes text as input, and outputs the following:
the
number of lines in the input
the number of characters in the input
the number of words in the input
Effectively, we're building the Unix program wc.
All characters, including the newline ('\n'), should be counted. Assume that only space(s), newline characters, and tab characters seperate words. That is: ' ', '\n', and '\t'.
Input is terminated by entering CTRL-D at any time. Recall
that CTRL-D triggers an EOF.
Instead of typing long paragraphs to test your program, you can use text file using I/O redirection. I/O redirection on Unix converts text files to standard input for programs. For example, if the text is stored in a file, textinput, you can input it into the program (a.out) by using I/O redirection as follows:
$
./a.out < textinput
(note that the $ denotes the command
prompt; you would not type the $)
The results will then be printed on the screen. Alternately, you can do:
$ ./a.out < textinput > results
The results will be printed in a file called, results
Use
the unix program wc to verify the correctness of your
program.
Your program must do the following:
Extra Credits (10 points):