I am reviewing material for my c final and have a couple of questions, for example i did this program below to add 1 and 2 to nodes and the print them, if i have them in main, they print if i try to make a function do it, it doesnt print anything, can anyone point to me why it doesnt?
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { int data; struct node *next; }; void traverse(); struct node *head; struct node *tail; struct node *p; int main() { struct node *head = '\0'; struct node *tail = '\0'; struct node *p; head = malloc(sizeof(struct node)); tail = malloc(sizeof(struct node)); head -> data = 1; head -> next = tail; tail -> data = 2; tail ->next = '\0'; traverse(); while(head) { printf("%d\n",head ->data); head=head ->next; } system("pause"); } void traverse() { struct node *p; p=head; while(p) { printf("%d\n",p ->data); p=p ->next; } }