User Tools

Site Tools


cs270:pointadt

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
cs270:pointadt [2020/09/10 12:46]
scarl
cs270:pointadt [2020/09/14 13:50] (current)
scarl
Line 18: Line 18:
  
   - Add code to test the ''​initPoint''​ function; this function dynamically allocates space for a Point and initializes it, much as a Java constructor does. The appropriate code will go in the ''​main''​ function in **pointTest.c**. Note the return value! Once you have the address of this new point, use ''​printPoint''​ to display it.   - Add code to test the ''​initPoint''​ function; this function dynamically allocates space for a Point and initializes it, much as a Java constructor does. The appropriate code will go in the ''​main''​ function in **pointTest.c**. Note the return value! Once you have the address of this new point, use ''​printPoint''​ to display it.
-  - In **point.c**,​ add checks for the case that calls to ''​malloc''​ return NULL. If this happens in ''​initPoint'',​ return the NULL value. If this happens in ''​readPoint'', ​keep going set label to NULL and return before the ''​strcpy''​.+  - In **point.c**,​ add checks for the case that calls to ''​malloc''​ return NULL. If this happens in ''​initPoint'',​ return the NULL value. If this happens in ''​readPoint'',​ set ''​label'' ​to NULL and return before the ''​strcpy''​, which would otherwise fail.
   - Since ''​readPoint''​ takes 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 ''​p''​ is in fact NULL.   - Since ''​readPoint''​ takes 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 ''​p''​ is in fact NULL.
   - Compile and test.   - Compile and test.
cs270/pointadt.txt ยท Last modified: 2020/09/14 13:50 by scarl