CSC 357 Lab 2
Getting Started with C Pointers and Structs



ISSUED: Monday, 9 April 2007
DUE: On or before 11:59:59PM Monday 16 April, via handin on falcon/hornet
POINTS POSSIBLE: 100
WEIGHT: 2% of total class grade
READING: Lecture Notes Week 2, "Gdb Basics" Handout, K&R Chapters 5 and 6

Overview

The following online location has a solution to a first programming assignment in CSC 103


classes/357/labs/2/GeneralList.java

It is the Java implementation of a class called "GeneralList" that provides a variety of list-manipulation operations. The javadoc for the class is in classes/357/labs/2/javadoc.

In the same directory as the Java code, there is a set of C program files, one of which is a skeleton for you to fill in. The skeleton file is classes/357/labs/2/general-list-skeleton.c.

The easiest way to obtain all of the necessary files is to use the -rp option with the UNIX cp command, on falcon/hornet

cd your-lab2-directory
cp -rp ~gfisher/classes/357/labs/2/* .

The only file you are implementing for this lab is general-list.c. You should use all of the other .c files in the directory as is. Hence, your job for this assignment is to fill in the skeleton, putting the result in the file named general-list.c.

Helpful Hints

This lab is about translating Java into C. While you're doing it, you should become familiar with the way C deals with structures, pointers, and arrays of them.

Note well the following recommendation in comment for the skeleton of general-list.c:

 * While this skeleton shows you which function bodies you need to fill in, I
 * strongly recommend that you do this lab by copying GeneralList.java to your
 * version of general-list.c, and then modifying the Java code into legal C
 * code.  This will save you a lot of time typing, and avoid simple errors of
 * translation.

As you do the Java-to-C translation, you will notice, among others, the following translation idioms:

One aspect of the Java-to-C translation that you can ignore for this lab is memory management, in particular, the freeing of unused memory in a C program. In this lab, and this lab only, you can pretend like C has a garbage collector, which of course, it does not. We will discuss an length the need to free memory properly in C programs, and you will have to do so in all future programs and labs.

I believe that you will find gdb very helpful in working on this assignment. See the "Gdb Basis" handout for information on using gdb.

Compiling and Running

There is a Makefile that compiles, executes, and tests the programs. To execute the Makefile, simply type the command make at the UNIX command prompt.

The testing runs as is it does for the programming assignments. Namely, if all test cases pass, there is no reported output. The testing script entails comparing the outputs of the C and Java versions of the program. The output of the two programs must be identical for the testing to be considered successful.

If you encounter errors from the test script, then you can use gdb on the compiled testing program general-list-test. I.e.,

> make
...
some execution errors are reported

> gdb general-list-test
(gdb) r
...
proceed with the debugging

Tasks

  1. Fill in all of the empty function bodies in the skeleton for general-list.c.

  2. Use gdb while you're doing your work. Although there are no specific deliverables for this gdb-use task, you will be asked questions about gdb in upcoming exams.


Deliverables

Submit exactly one file -- the completed general-list.c.

Scoring Details

5 points per properly-implemented function.

Collaboration Allowed

Lab partners may submit the same program.

How to Submit the Deliverables

Submit your deliverable using the handin program on falcon/hornet. The assignment name is lab2.

If lab partners elect to submit the same program, they must still run handin individually to submit their work.


index | lectures | labs | programs | handouts | solutions | examples | documentation | bin