Lisa b

Lisa b

  • NA
  • 31
  • 15.8k

C program that reads in two words, should be readable.

May 9 2013 5:10 AM
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.



Attachment: file.zip

Answers (9)