Attempted to re-write the functions to avoid the whole global problem and using case 1 got:
Declared in main:
struct point *ptr=NULL;
Code:
case 1:
{
ptr=InputRecord();
AddToEnd(ptr);
break;
}
Code:
struct point *InputRecord (void)
{
struct point *ptrN=malloc(sizeof(struct point));
if(ptrN==NULL)
{
printf("No more memory.\n");
exit(1);
}
printf("Please enter the 2 Data points(x and y):\n");
scanf("%d%d",&ptrN->x, &ptrN->y);
printf("Please enter the label:\n");
scanf("%s", ptrN->label);
return ptrN; // return pointer to new struct
}
Code:
void AddToEnd(struct point *ptrN)
{
if(ptrFirst==NULL)
ptrFirst=ptrN;
ptrLast->ptrNext=ptrN;
ptrN->ptrNext=NULL;
ptrLast=ptrN;
}
Code:
void PrintList(struct point *ptrF)
{
while(ptrF != NULL)
{
printf("Label: %s\nx: %d y:%d\n\n", ptrF->label, ptrF->x, ptrF->y);
ptrF = ptrF->ptrNext; // this is how a list is traversed
}
}
Note I still kept these global but I think it helps avoid the problem, they still don't work, just thought I would try that to get rid of the global thing, and make it easier to work with. I tried anyway..
struct point *ptrFirst = NULL;
struct point *ptrLast = NULL;