View Single Post
Old Dec 14th, 2007, 5:46 AM   #7
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,221
Rep Power: 5 grumpy is on a distinguished road
Re: Linked List problem - Deleting a node

Sorry, Salem, you missed the real problem ...

There is also a problem that will emerge when creating the list. head_ptr is never initialised so it points to anything valid (i.e. a data structure). The first call to add_user will therefore introduce undefined behaviour. The code that creates a struct pointed at by current is fine, although it stores the address of the created struct in a local variable. Then move_current_to_end() is called, which does;
current_ptr=head_ptr;
while(current_ptr->next!=NULL)
{
    current_ptr=current_ptr->next;
}
which is chock full of undefined behaviour since head_ptr has never been initialised..... if current_ptr does not point at anything valid, accessing the value of current_ptr->next yields undefined behaviour.
grumpy is offline   Reply With Quote