Exercises

September 11, 2006

  1. Design and implement a program that prompts the user for a word and a file name and counts the number of times the given word appears in the file. Your program will keep a count of the number of lines in the input file and produce an output file that contains the line number and line for each line on which the word appears. For example, if your program was counting the number of occurrences of the word “stormy”, you might have the following entry in your output file to indicate that the word appears on line 5: “5: It was a dark and stormy night.” You can use the file dracula.txt to test your program -- search for the word “vampire”.

Sami Rollins