Hello again.
I was studying Linked list, I'm beginner. Where is my mistake ? Please help me.
Code:
#include <stdio.h>#include <stdlib.h>
struct listnode{
int num;
struct listnode *nextPtr;
};
typedef struct listnode ListNode;
ListNode *head, *p;
int main(){
int choice = 1;
p = (ListNode*)malloc(sizeof(ListNode));
head = p;
while(choice){
printf("Enter number: ");
scanf("%d",&p->num);
p = p->nextPtr;
p = (ListNode*)malloc(sizeof(ListNode));
printf("Continue or break(1-0)");
scanf("%d",&choice);
}
p->nextPtr = NULL;
traverseTheList();
return 0;
}
void traverseTheList(){
p = head;
printf("\n");
printf("\n");
while( p!=NULL ){
printf("%d",p->num);
p = p->nextPtr;
printf("\n");
}
}