This is a review of C coding style, memory management,
file I/O, and an introduction to basic Lexical Analysis. Design,
write, and thoroughly test the following C program:
- Build a robust string prompting interface that
safely inputs a text string ending in a newline
or EOF:
- Must not overflow any buffers, no matter
how long the input string is.
- If the internal buffer cannot handle all
of the input, the user is asked to retype
it.
- Handles blanks.
- Use your string interface to obtain file names
for a character-by-character file analysis
program:
- Prompt for an input file name and an
output file name using your string
interface.
- Open the input file.
- Allocate table space to hold a character
count table.
- Pass the file pointer and a pointer to
the table to a function that does
this:
- Uses fgetc() to read and
count how many times each
character occurs in the file.
- Fills in the count in the table.
- On return from the function, in main(),
do this:
- Open the output file.
- Write a formatted version of the
table of character counts to the
output file.
- Have main() loop for as many files
as the user wants to process. (How will
the program do this?)
- Follow the C Programming Style guidelines
carefully.
- De-allocate any dynamic storage used.
- Close all files opened.
- Issue appropriate messages if any
operation in your program fails.
- Where possible, find out from the
operating system why the operation
failed.
(E.g. "no permission",
"file not found", "I/O
error", "disk full", etc.)
- Bonus Marks:
- Modify the program so that if the user
enters a dash ('-') for a file name, the
terminal is used instead of opening a
file, whether for the input file name or
for the output file name. This will be
useful for testing your upcoming
assignments on "live" input
rather than having to always put the
input into a file first.
Your assignment is due in the Ian Allen assignment box
before 10am Wednesday, May 14, 1997.