Question: 2. (4pt) Complete the following program that reads a given text file and counts the number of a given keyword in it. Count only the

 2. (4pt) Complete the following program that reads a given textfile and counts the number of a given keyword in it. Count

2. (4pt) Complete the following program that reads a given text file and counts the number of a given keyword in it. Count only the whole words that are separated by one or more white characters (e.g., space ' ' newline ' ' etc.) You can call isspace (char ch) in ctype.h to check if ch is a white space character. If yes, it returns 1, else it returns 0. The input file name and the keyword will be given as command line arguments. Here is an example. Suppose we have the following lines in input.txt many keywords and spaces it some words like aaaa and bbbbare this file has but important is more important so find how many time it appears. When we execute your prog as follows prog input.txt aaaa it should print out : word aaaa appears 2 times. prog input.txt aa it should print out : word aa appears 0 times Implement your program in the next page. If needed, you can assume that the length of a word will be less than 100 characters Hint: First implement a function char *get next word (FILE *fp); which reads one word at a time from the file pointed by fp. It skips white characters and puts all the other characters in a dynamically allocated memory until getting another white space character. It then returns its address. If there is no more words, it returns NULL

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!