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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started