Quote (Eep @ Mar 13 2013 01:20am)
Are you missing a for loop in that remove function?
anyway, drawing pictures always helps with pointer problems
consider my drawing: (Not an artist FYI)
http://img685.imageshack.us/img685/4328/pointerlulz.jpg
Notice:
Node *temp = you are allocating space for another node object
Temp points to list->next
you free temp (which was list->next)
but it would appear to me that whatever memory temp used originally never got freed?
Now I am not a C master by any means but it seems to me that you would need to free another thing
Node *temp doesn't allocate memory, it just creates a pointer to a node
Temp is just a pointer to a node, temp eventually points to the allocated space at list->next
Freeing temp, should free the allocated memory at the address it points to
There doesn't need to be a loop in the removal of the 2nd element because it can be done easily without one and there's no need to iterate through the entire list
This post was edited by lopelurag on Mar 12 2013 11:30pm