I am having trouble adding a second node to a doubly linked list. I define my list as follows:
Code:
typedef struct Node {
char command[256];
int length;
struct Node *prev;
struct Node *next;
} userInput;
typedef struct q {
userInput *head;
userInput *tail;
} inputQ;
inputQ input = {NULL, NULL};
userInput *newNode;
For the 1st node, I do this:
Code:
input.head = newNode;
input.tail = newNode;
newNode->prev = NULL;
newNode->next = NULL;
And, for the 2nd node, I do this:
Code:
newNode->prev = input.tail;
input.tail->next = newNode;
input.tail = newNode;
Now, when I iterate back through my list (I want to start at the tail and work my way towards the head), I can only ever get the 1st node to print, then the 2nd node is garbage, which means, to me, that I've linked something wrong. Can anyone please tell me where?
Thank you all so much!