Hey guys I am teaching myself the C language and came across a program assignement that i think would be helpful to know how to do. Here is the assignement :
Write a C program that will read a series of lines of input text (each input text line will not exceed 80 characters in length) and determine the number of each unique "word"s found in the input. While finding the words, several statistics about the words and text are to be accumulated.
A "word" is defined for this assignment as a series of non-white-space characters with leading and trailing punctuation characters removed. You are to consider punctuation characters to be all printing characters except letters, digits, and the space. C can automatically identify punctuation characters using the ispunct() function.
Note that punctuation characters inside a word (such as teacher's) are considered part of the word, and sequences of numbers (like 1234) would also be considered valid words, based on the assignment's definition of a word.
The program should determine each word found in a series of input lines, and accumulate the following characteristics about the words:
After all of the words have been determined, display a summary report of each of the characteristics described above.
- The number of short-length words (words with a length less than 6).
- The number of medium-length words (words with a length greater than 5 but less than 12).
- The number of long-length words (words with a length greater than 11).
- The number of capitalized words.
- The number of common words ("the", "of", "a", "is", "that", "are"), without worrying about case. Treat the words case-insensitively. Accumulate one total for all of the common words listed.
- The number of sentences (a sentence is considered to be (for this assignment) to be indicated by a word that has either a period, exclamation point, or a question mark someone in its trailing punctuation).
- You code should follow consistent indentation, use well-chosen variable names, and be written so as to be easily read.
- You should NOT include printf() prompt statements in your code as you will be reading data from a file, using Linux redirection (./a.out < datafile.dat).
I would greatly appreciate if someone could show me the code on how to do this as it would be very useful to study so I further my knowledge of the language. Thank you!
Here is the text for the file that is supposed to be used.
The teacher announced: "This is a simple example
showing several sentences of text." The students
where instantaneously amazed!
With surprise, the teacher's dog stood up and barked
"Ruff! Ruff!! Ruff!!!" The students were surprised
and burst into applause, much to the teacher's chagrin.
That is all, folks! [86 and out].