The code above is in a while loop that terminate once the user quits the program. userFirst is declared: char userFirst[50];Code:struct link { char *listName; struct link *next; list *currentList; /*pointer to a double-linked list */ }; struct link *first = NULL; struct link *current = NULL; struct link *previous = NULL; current = (struct link*) malloc (sizeof(struct link)); if (first == NULL) { first = current; } if (previous != NULL) { previous -> next = current; } //set contents of the new link structure. current -> listName = userFirst; current -> next = NULL; previous = current; /* save address of last link structure */ current = first; printSingleList(¤t);
If the user enters c Parameter1 then I create a node with the name Parameter. I then enter:
c list1
c list2
c list3
Now I go and print out the list from the first node and get:
list3 list3 list3, instead of list1 list2 list3. Whatever am I doing wrong?