Next: About this document
Using the vi editor, write a C program on the Sun cluster that prompts the user
for an input file name and an output file name. The input file should contain
words (text) in any format. A word is defined as any string of characters
separated from other strings of characters by one or more blanks, tabs,
or newlines. The output file created by your program should
contain the same words in the same order as the input file, but each line
of the output file except that last should contain exactly 5 words. The
last line of words in the output file will contain less than 5 words if the
number of words in the input file is not a multiple of 5. The final line
of the output file should contain a count of the total number of words in
the input file.
More detailed specifications include:
- The program must check that the input file and output file are opened
correctly. If not, the program should prompt for another file name.
See:
~taw2/pub/fileadd.c
for an example of how to do this. - The program should work correctly if the input file exists, but is
empty. That is, it should create an output file containing nothing
except the sum of the total number of words in the input file (0).
- The program may assume that no word in the input file contains
more than 40 characters.
- Words on the same line in the output file should be separated by a
single space, no matter how many spaces, tabs, and newlines separated
them in the input file.
- The file:
~taw2/pub/outwprog4
contains the result of running my program for this assignment on the file:
~taw2/pub/prog4.c
- For 5 points extra credit, modify your program so that if the output
file name entered by the user is the name of a file that already exists,
your program notifies the user of this fact and asks the user to confirm
that this file should be used. If the user decides not to use this file
as the output file, your program should prompt the user for another output
file name.
- To hand in:
- Either turn in a print out of your source code, or email me
(wahls@psu.edu) the file containing your source code.
If you email me the program, I will email you your score and any comments
on your program sometime after the due date. I will also save a copy of
your program to prevent later disputes.
- Your code will be graded on correctness, programming style,
readability, the clarity
of messages printed for the user and appropriate use of comments.
Next: About this document
Tim Wahls
Wed Mar 19 11:22:15 EST 1997