OK, there's a bug here:
The problem is that P is only assigned a value if (units[low]->IDs == NULL). If that condition is not true, P does not get assigned.Code:void add_student(int loopnum)
{
char unit_name[101];
int low, student_ID;
Position P;
low=0;
scanf("%d %s", &student_ID, unit_name);
units[loopnum] = (unit_struct*) malloc(sizeof(unit_struct));
units[loopnum]->name = malloc(sizeof(unit_name)+1);
while(strcmp(units[low]->name, unit_name) !=0)
{
low++;
}
if(units[low]->IDs == NULL)
{
units[low]->IDs = MakeEmpty(NULL);
P = Header(units[low]->IDs);
}
InsertInOrder(student_ID, units[low]->IDs);
printf ("AddStud: pointer P pointing to: %p\n", P);
P = Advance(P);
}
In either case, you use P in the call : P = Advance(P); which is wrong!
I put a printf statement in to display the contents of the pointer to prove it:
Also, the Advance function does nothing for this variable as it's local to the add_student function. I'm not sure what you're trying to do with it.Code:1
a
4
1
a
AddStud: pointer P pointing to: 0x970c10
4
2
a
AddStud: pointer P pointing to: 0x0
Segmentation fault (core dumped)
Have fun fixing......