Originally posted by Codeplug
del_node() and del_list() are fine.
The problem is in add_node() when *headptr == NULL. You assign tmp to *headptr but tmp->next is uninitialized.

gg
in that case, can i just set tmp->next to NULL? when the headptr is NULL, i'm assuming that the list is empty, so tmp->next wouldn't have to be initialized? thanks

Originally posted by Sebastiani
>> tmp->next = *headptr;

Here, you are inserting the new node *in front* the head (meaning you'll never see it again). You need to traverse to the end of the list, and point the last node's next ptr to the new node. The new node must have it's next ptr set to NULL.

Then the very next line goes:

>> *headptr = tmp;

That's a memory leak. headptr now points to temp, and the memory headptr *was* pointing to is lost forever (so to speak).

Everything else is OK.
when i'm inserting the new node *in front* of the head pointer, i thought i was just moving the old headptr to the the new headptr's next. first i assign the current headptr to the tmp->next, then i assign the tmp to headptr as the new head pointer. so i don't see how it'll be lost or why i would have to traverse to the end..

Code:
tmp->data = value;
        if( *headptr == NULL ) { /* if the head pointer is empty */
            *headptr = tmp;
            return 0;
in that bit, headptr doesn't actually have any memory allocated to it, correct? so assigning tmp (which points to allocated memory) to headptr just gives headptr allocated memory to point to, right?

thanks for all of your guys' help

scrappy