Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

Is every knowledge area in only one process group?

Answered: 1 week ago

Question

4-6 Is there a digital divide? If so, why does it matter?

Answered: 1 week ago