CST 8152 - Assignment One
Due 10am Wednesday May 14, 1997
Purpose and Instructions:
- This is a review of C coding style, memory management,
file I/O, and an introduction to basic Lexical Analysis.
write, and thoroughly test the following C program:
- Build a robust string prompting interface that
safely inputs a text string ending in a newline
- 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
- Handles blanks.
- Use your string interface to obtain file names
for a character-by-character file analysis
- Prompt for an input file name and an
output file name using your string
- Open the input file.
- Allocate table space to hold a character
- Pass the file pointer and a pointer to
the table to a function that does
- 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(),
- Open the output file.
- Write a formatted version of the
table of character counts to the
- 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
- 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
(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.
Deliverables for this assignment:
- The fully documented source listing of your program
(including your own .h files).
The submission must follow the online course submission guidelines.
- A description or listing of your input test file(s) (and
output, if appropriate) showing how you tested your input
routine and your counting function.
- I will show you how to deposit your assignment
source code into a directory on the Algonquin server when
the server is ready.
- The aggregate of all assignment marks comprises
20% of your final mark. All assignments must be
completed satisfactorily to get credit for the course.
review the C Programming Style guidelines. Assignments
are marked for clarity and simplicity as well as
Late assignments are handled according to the policy
given in the course outline.
Inside every big program is a little program
struggling to get out.
C Programming Style
- write it once, and only once
- modifications require one change
- less code is better code
- only -1, 0, and 1 as constants
- #define everything else
- use enum
- boolean != NULL != 0 != \0
- keep your data types separate
- check and validate input (including excess)
- don't ignore any user input
- dont modify function arguments
- copy the arguments to temporaries if needed
- fopen/fclose at same level
- don't hide file open/close in functions
- check function return codes
- if it can fail, test it
- write cover functions to avoid duplicating code
- read input in only one place
- avoid global variables
- use the static keyword wherever possible
- print really good error messages
- not "too big"; instead: "biger
than %d bytes"
- get the code right first, then optimize
- put short, explanatory comments at the start of blocks of
Ian D. Allen CST8152 Home Page - Summer