CIS 1057: Homework 10

Handed out: 11/02/10
Due: by 10:00am on 11/08/10

Write a program that does the same as the Unix utility wc. That is, given as command line parameter the name of a (text) file, it prints out on a new line the number of lines, words, and characters in that file and its name. A line is defined as a sequence of characters terminated by '\n' or by the end of file.
A word is defined as a sequence of non-blank characters that is delimited by blank characters like space, tab, new line, end of file.

Suppose that you have compiled your program hmw10.c into the file a.out, then you would execute:

   % a.out hmw10.c
and your program would say how many lines, words, and characters are in hmw10.c. For example,
   27  138  473 hmw10.c

As a comment at the beginning of your program you should do a case analysis for this problem: problem statement, analysis, design, implementation, and testing.

To read from a file we need to open the file, then read its lines. The following program shows you how to use a file.