Code:
arxeio=first; s=0;
while(arxeio!=NULL)
{
if (arxeio->aStudent->idNumber==iddel)
{
printf("erasing id %d",arxeio->aStudent->idNumber);
if(first->aStudent->idNumber==iddel) /* first node to be deleted) */
{
temp1 = first->next;
free(first);
first= temp1;
s=1;
}
}
if (arxeio->next->aStudent->idNumber==iddel)
{
if (arxeio->next!=NULL)
{
temp1=arxeio->next->next;
free(arxeio->next);
arxeio->next=temp1;
}
s=1;
}
arxeio=arxeio->next;
}
if (s!=1)
{
printf("error! wrong id");
}
the list contains the following nodes
first:
alex
4598
------
john
2245
------
tom
4445
if i ask to delete the id 4445 my program works just fine,if i ask to delete any other node the program stops.any idea why is this happening?