Question: C Program question: Write a program that counts the number of occurrences of a substring within a file. The program must allow the user to

C Program question:

Write a program that counts the number of occurrences of a substring within a file. The program must allow the user to enter both the substring the user wants to search for and the name of the file to be searched. The output message must include the number of occurrences of the substring, the substring, and the name of the file searched.

This is not an array problem. It is a file and string problem. It is not possible to store all the strings read from the file in some huge two-dimensional array. The file will likely contain too many strings for this.

For example, the program should run like this:

Enter the string that you want to search for:

the

Enter the name of the file you want to search through:

helpme.txt

There were 42 occurrences of the string "the" within the file helpme.txt.

How can one do this?

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!