CSC 161 Schedule Readings Labs & Projects Homework Deadlines Resources

Elementary Text Analysis

Write a C program that takes the name of a file as a command-line argument, opens the file, reads through it to determine the number of words in each sentence, displays the total number of words and sentences, and computes the average number of words per sentence. The results should be printed in a table (at standard output), such as shown below:

./analyze-text comp.text
     This program counts words and sentences in file "comp.text ".

     Sentence:  1    Words: 29
     Sentence:  2    Words: 41
     Sentence:  3    Words: 16
     Sentence:  4    Words: 22
     Sentence:  5    Words: 44
     Sentence:  6    Words: 14
     Sentence:  7    Words: 32

     File "comp.text" contains 198 words words in 7 sentences
     for an average of 28.3 words per sentence.

General notes