用C编写文本文件中的关键词查找与统计
Write a C program that reads in two words, then searches for all occurrences of these words within a text file. Your program must display the first line that each word occurs in and also display how many times the words occur in the file. Your program must not be case sensitive – for example, the word “APPLE” must be recognised to be the same word as “apple”. You will need a file (or files) to test your program. You can use an existing file or make a new one. The file must be a text file. It cannot be a Word document or any file that requires a special format. Note that if the words do not occur in the file, you must display an appropriate message.
Example:
Enter the first word: the
Enter the second word: Bilbo
Enter the name of the text file: History.txt
The word ‘the’ first appears in line 3 which is:
The 8th Route Army infiltrated behind enemy lines in Northern China
The word ‘the’ appears 372 times in the file.
The word ‘Bilbo’ does not appear in the file.
[解决办法]