The instructor uses a function to test my code to see if it worked, and then the test function is called in main. This is the code to test my function:
Code:
void testAddPointAtEnd(){
char inputBuffer[MAX_LINE];
inputBuffer[MAX_LINE-1] = '\0';
char *inputString;
PointListNode *list = NULL;
Point* newPoint = NULL;
float xy[2];
int count;
startTest("add_point_at_end");
//Now allow the user to enter as many points as they want
printf("Creating point list - Enter as many points as you want, and leave a line blank when you are done.\n");
count = 0;
while (1){
printf("Enter x & y for point %d: ",count+1);
fflush(stdout);
if(!(inputString = testPrompt(NULL,inputBuffer,sizeof(inputBuffer))))
break;
if (readNFloats(inputString,xy,2) != 2){
printf("\t Wrong number of values provided - ending list.\n");
break;
}
list = addPointToList(list,allocateNewPoint(xy[0],xy[1]));
count++;
}
if (count == 0){
printf("\t No data provided - Skipping test.\n\n");
return;
}
list = reversePointList(list);
printf("The list of points is: ");
printPointList(list);
printf("\n");
printf("Enter x & y for a point to add at the end of the list: ");
fflush(stdout);
if(!(inputString = testPrompt("",inputBuffer,sizeof(inputBuffer))))
return;
if (readNFloats(inputString,xy,2) != 2){
printf("\t Wrong number of values provided - skipping test.\n\n");
return;
}
newPoint = allocateNewPoint(xy[0],xy[1]);
printf("Adding the point (%.2f,%.2f) to the end of the list with add_point_at_end\n",newPoint->x,newPoint->y);
add_point_at_end(list,newPoint);
printf("The modified list of points is: ");
printPointList(list);
printf("\n");
freePointList(list);
fflush(stdout);
} /* testAddPointAtEnd */