In this section you'll work with the files that make up our simple Point ADT (Abstract Data Type). To start, download the files from the webserver
Make sure they compile and run as is. To compile a program made up of multiple files, add each .c files to the gcc command. Also, this program uses
sqrt from math.h so we need the
-lm flag to pull in the math library. So the gcc command looks like this:
gcc -Wall -o pointTest point.c pointTest.c -lm
initPointfunction; this function dynamically allocates space for a Point and initializes it, much as a Java constructor does. The appropriate code will go in the
mainfunction in pointTest.c. Note the return value! Once you have the address of this new point, use
printPointto display it.
mallocreturn NULL. If this happens in
initPoint, return the NULL value. If this happens in
labelto NULL and return before the
strcpy, which would otherwise fail.
readPointtakes a pointer variable as its argument, it's a good idea to check that it isn't NULL before getting too far into the function. Do this check first thing, and just return straightaway if
pis in fact NULL.
As always, if you run out of time or are working remotely, send me an e-mail containing screenshots of the working programs
by the end of the day for full credit. Also send the C files point.c and pointTest.c so I can see your NULL checks. This exercise is due before 5pm Friday. Schedule a meeting if you have difficulties.