Word Search
- Description:
- You just received a fancy new job as a contract worker in a downtown office. On your first day, your new boss tells that your job entails sifting through electronic files searching for key words and making a list of all the lines the words appear in. He then tells you that this is your only project for the summer. This job is pretty easy, except for the fact that there exist a large set of files you must sift through. Since you are a contract worker and get paid by the job - not the hour - you decide to search for a way to work more efficiently.
- Your job is to write a program, that searches through a file for a specific word. If the word is found, you will output to the screen the line number, and the complete line of text the word was found in.
- Requirements:
-
- This program must use command line arguments, and the usage should look like the example below:
-
- ./a.out <search word> <filename>
- - Where a.out is the executable
- search word, is the word we are looking for
- filename, is the name of the file we are looking in
- If the user doesn't use the program properly, you must display an error and abort the process.
-
- Your output may look similar to this:
- >./a.out boat document1.txt
- Line 1:
The sail boat had a large red sail. Fishermen complained that it took too much room by the dock.
Line 15:
Next Saturday, everyone will get together for a picnic by the beach. This way, we'll get to see the boats pass by.
-
- Additional/Optional Requirements:
- Instead of just printing the information to the screen, have it print to a file with the same name as the input file, except with a ".sol" extension. This way you'll be able to easily determine which solution file goes with which document
- When you find the capitalize the word when you print it to the solution file
- Concepts:
- File Input/Output
- Looping structures
- Algorithms