Question: Write a C program wordCount, to print a frequency count of all the words coming from input from stdin. The list of words and their
Write a C program wordCount, to print a frequency count of all the words coming from input from stdin. The list of words and their counts will be listed in alphabetical (lexigraphical) order as specified below:
Input:
A sequence of words from stdin.
Definition of words
Words are strings that are separated by white space. Therefore, you can (and should) use scanf to read in each string as a word. However, we must do some further processing. Imagine the input includes the line: "Cats rained down on other cats inlucding the purple cats." Notice that the following words appear in the input "Cats", "cats", and "cats." We would like to count them all as the same word, "cats". To do this we will process every string separated by white space as follows:
1. Convert all the uppercase letters to lowercase.
2. Strip all the nonalphabetic symbols from the front of the string.
3. Strip all the nonalphabetic symbols from the end of the string.
Following this process "cats!" becomes "cats", "**WARNING**" becomes "warning", "Planet9" becomes "planet". This is not a perfect solution. For example, "you're" stays "you're", but we don't want the program to be too complex. Notice that this procedure can leave you with an empty string if the string has no alphabetic characters. For example, "99" and "&" both become "". Your program should ignore such strings. They are NOT considered to be errors in the input, nor should they be included in the word count.
Output:
After all the input has been read, your program should print out the list of words together with the number of times each appeared. Each word and count should be on its own line. Use the following print statement:
printf("%s %d ", word, num)
where word is the word and num is the number of times it appeared in the input. These words should be printed in alphabetical (lexigraphical) order.
For example, the input below:
I am the eggman. You are the eggman. I am the Walrus.
contains 12 words and its output should be:
am 2
are 1
eggman 2
i 2
the 3
walrus 1
you 1
Assumptions: You can assume that each of the words read from the input is at most 128 characters.
Error Conditions: none
Makefile: In addition to your source files, you should submit a make file named Makefile that supports at least the following functionality:
make wordCount
Compiles the C source code to create an executable named wordCount. The compiler options used should include -Wall.
Restrictions:
The purpose of this assignment is to get you used to using structs and pointers. You may therefore NOT allocate a bunch of memory for a big array and then resize it as necessary. Instead you should create something like a linked list that uses exactly the amount of memory needed to keep track of the data. That said, you do have freedom in implementation. You may choose to store all the words and then calculate the counts and order, or you may choose to keep track of those things as you process the input.
Example:
Suppose the input consists of the following lines:
It was the best of times,
it was the worst of times,
Then the output should be
best 1
it 2
of 2
the 2
times 2
was 2
worst 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
