IPC144 Word Problem – Working with Files
Write a C program that when run will ask the user for a string pattern. The main program will prompt the user to enter a string pattern. The program will then read the data file called file.txt and will display the number of times that the pattern matches in the contents of file.txt .
You will be creating 2 functions:
int
getContents(char pattern[]) - Will read the contents of the file
file.txt line-by-line
and during
each cycle will call the countMatch() function.
The getContents()
function will accumulate the number
of matches from the
countMatch() function and will then
return the total number of pattern
matches.
int
countMatch(char contents[], char pattern[]) -
Will count and return the number of
occurrences of
the pattern in the line
that is read from the file
when this
function is called from within the
getContents()
function.