The very fisrt step before add a node is to initialize the head/last pointers to NULL propably into main.
Decide the way new items should be inserted to list. (Let's say at the end)
In the beggining (empty list) head and last are pointing to the same node (aka NULL)
Adding an item:
1. Store the new value to an int
2. Allocate memory (malloc) of the new node to temp pointer. Initialize it. (temp->next = NULL, value = 0 etc)
3a. if this is the first time adding item then, both head/last pointers should point to temp and next pointer of temp to NULL
3b. else, next pointer of last node should point to temp and next of temp should point to NULL.
4. Copy the new value and return new node
The fifth rule : A real programmer doesn't eat until debugging ends.
Attachment 12139