Hi all!
So our T.A. gave us a function to use in our programming assignment as follows:
struct node *delete_from_list(struct node *list, int examnum)
{
struct node *cur, *prev;
for (cur = list, prev = NULL;
cur != NULL && cur->examNumber != examnum;
prev = cur, cur =cur ->next)
;
if(cur == NULL)
{
return list; //n was not found
}
if (prev == NULL)
list = list ->next;
//n was in the first node
else
prev->next = cur->next; //n was in another node
free(cur);
return list;
}
After about the third time this function is called, I get an error at the free(cur) second line from the bottom saying Windows has inserted a breakpoint possibly due to heap corruption and a few other technical sounding phrases, but I can't make anything out of it. Any idea what's wrong? Is this enough context?