Lab 13
Strings, strtok and File
I/O
Due November 26, 2014 at 11:59 PM
Background Preparation:
Review file processing, strtok(), strcat() and other cstring operations.
Description:
You are to create a (very) simple word processor.
Your program will prompt the user to enter the name of an
input file containing text ("Lab13_bad.txt"). It will then prompt you
for the name of an output file. Your program will open the input file
for reading, and open the output file for writing. The program will
then read the input file, one line at a time. After each line is read,
the line will be printed to the screen and a prompt will appear asking
the user which word (as a position in the sentence) should be removed
from the line. For instance the program might print the following sentence and prompt:
You are to NARF!
create a (very) simple word processor.
Enter position of word to delete (Start counting at 0). Enter -1 to skip deletion:
The user will enter the value 3 to remove "NARF!" from the sentence
(remember that the first word is in position 0).
The program will then tokenize the words in the sentence using
strtok(), and create a new sentence without the chosen word using
strcat(). It will then write this new sentence to the output file.
The chosen word will be saved in a separate array to be output at the end of the program.
Your program will continue in this fashion until all the
sentences in the original input file have been processed. After all of
the sentences have been processed, close the output file and write the
list of words that were deleted from each line to stdout.
Note that your program should be able to handle sentences
where the user does not wish to remove a word. The user will
indicate that they do not wish to remove a word by entering a negative
value.
You may assume that the file will contain less than 100 lines, and that each line in the file will be less than 101
characters (including the null terminator). Remember to close both the input and output files before
exiting your program.
Be sure to include comments within your code that explain in high-level
terms what the various parts of your code are doing. Also, include
preconditions and postconditions as appropriate.
Development and
Submission Instructions:
Feel
free to develop your
program in any environment you choose. However, as with previous
assignments, before submitting your assignment, you must test it on
Zeus to be sure it works properly (mason will no longer used as a
testbed for this course). Create a typescript that first lists the
contents of your
working directory and confirms the system you are on, use the unix
"cat" command to print the contents of the input file and your
program to the screen. Then compile your program using gcc and run it.
Before you complete the typescript, use the ls command to
show the contents of your working directory after your program has
executed, and "cat" the contents of the output file to the screen.
Create an archive file using the tar command that contains the typescript, the source file containing your program and the text files. Submit this archive file to
Blackboard as Lab 13. Use whatever functions,
parameters and return statements you wish to organize your code and
ensure that it works correctly.