The purpose of this assignment is to test your programming skills and to prepare you for future assignments.
Each time you start a new part of this assignment, create a new directory. When you are finished, you should have an assign1 directory with subdirectories part0, part1, and part2. When creating one of these directories, start by copying into it the contents of the previous directory. Each time you write a main program, use lint and make sure you understand all of the warning messages. Save the lint output. Read this infomation about running lint.
Obtaining help
You are to do this assignment on your own, but you may ask me for help at any
time. The earlier you start the assignment, the more help will be available.
You may obtain help from me before or after class, by coming to my office,
or by email.
Read through the entire assignment and look at the cover sheet before writing any code. You will be graded not only on the correctness of your programs, but their clarity and the methods you used for testing.
Part 0:
Use the information from Recitation 1 to do this part.
Write a function:
int show_info(char *path);
which outputs to standard output
the the following information on separate lines in the order given:
Write a main program called test_show_info.c that takes one
command line parameter. The program starts by printing to standard error
a line in the form:
This program was written by ...
It calls show_info with this command line parameter
and prints out an appropriate error message (to standard error)
if not successful.
Nothing else should be output.
Test this program with several different file names including ones that do not
exist.
Use separate compilation and a makefile.
Part 1:
Write the function:
int serialize(char *buf, int bufsize, char *path);
It attempts to fill the buf with a string containing the
following information as printing characters on three separate lines
(separated by newline characters).
Write a main program called test_serialize.c to test this function. It should start out like test_show_info but call serialize with a buffer of an appropriate size. It should print the contents of buf on success or an error message on failure.
Do as many tests as necessary to convince me that the function is working properly.
Part 2:
Write the function:
int deserialize(char *buf, char *name, int namesize, int *size, int *sec);
The first parameter is a string that may have been generated by
serialize. The
second parameter is a buffer of size namesize. It attempts to fill
in the values of the name, size and number of seconds in these parameters.
It returns 1 on success and 0 on failure. Failure can occur if the name
will not fit in namesize bytes, if the first parameter does
not contain exactly 3 lines, or if any of the numeric fields are invalid.
Write a main program called test_deserialize.c to test this function. You should have a number of tests in this program. The output should be designed so that it is easy to see what tests were performed and what the results were.
Handing in your program:
Use this cover sheet. Consecutively number all of
the other pages you turn in. Each page that contains your work should have
a number on it. Make sure you have answered the questions from the cover sheet.
Turn this in at the beginning of lecture on the due date.