4) Set up a new text file. Use any editor (e.g. notepad) to type data into the file. The contents of the file must be sentences and each sentence must end with a full stop. Lines can be any length. Note that the only punctuation in the file is full stops so there are no commas,question marks,quote marks, etc.
As an example, the first few lines of the file may look like this:
Eleanor of Aquitaine married King Henry II of England on
18 May 1152. The 8th Route Army infiltrated behind enemy lines in
Northern China in 1943. Idi Amin was president of Uganda in 1972.
Write a C program that reads in two words and searches for all occurrences of these words in the file you set up in Question 4 above. Remember that you do not need the full path name of the file if it is in the same folder that you are working in. Your program must display the first line that each word occurs in and also display how many times the two 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". 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 2 which is:
18 May 1152. The 8th Route Army infiltrated behind enemy lines in
The word 'the' appears 372 times in the file.
The word 'Bilbo' does not appear in the file.
Loading
VulpesPosted May 10, 2013, 7:04 AM
Anyway, as it was really an unnecessary refinement, I've got rid of it altogether and it now seems to be working fine.
Also noticed that I'd forgotten to close the file and so have added a line to do that.
Here's the revised version:
Lisa bPosted May 10, 2013, 5:08 AM
Lisa bPosted May 10, 2013, 5:07 AM
VulpesPosted May 10, 2013, 4:58 AM
Can you post or attach your file please and I'll try and track down the error.
Lisa bPosted May 10, 2013, 1:59 AM
The word 'the' appears 372 times in the file.
The word 'Bilbo' does not appear in the file.
when the program tries to run that step it crashes. anybody else's help would be great
thank you
AnhurPosted May 9, 2013, 9:58 PM
VulpesPosted May 9, 2013, 5:12 PM
#include
if you're using gcc rather than the MS compiler.
Lisa bPosted May 9, 2013, 4:30 PM
What would 'tolower' be declared as?
thanks
VulpesPosted May 9, 2013, 9:23 AM