0

My link list is not working when i am putting value and location manually

//I don't know why my code is not working.I am making a basic linked list // but i am putting values in it manually. But it is stopping during run time. //Anyone please help me and tell me the error. I will really appreciate it. #include <stdio.h> #include <stdlib.h> void display(); struct node { int data; struct node *next; }; int main() { struct node * head=NULL,*first,*second,*third,*forth,*fifth,*newnode; newnode=(struct node *)malloc(sizeof(struct node)); newnode->data=1; newnode->next=second; head=first=newnode; newnode=(struct node*)malloc(sizeof(struct node)); newnode->data=2; newnode->next=third; second=newnode; newnode=(struct node*)malloc(sizeof(struct node)); newnode->data=3; newnode->next=forth; third=newnode; newnode=(struct node*)malloc(sizeof(struct node)); newnode->data=4; newnode->next=fifth; forth=newnode; newnode=(struct node*)malloc(sizeof(struct node)); newnode->data=5; newnode->next=NULL; fifth=newnode; void display() { newnode=first; while(newnode!=NULL) { printf("->%d",newnode->data); newnode=newnode->next; } } display(); return 0; }

4th Oct 2020, 3:49 PM
Karan singh majila
Karan singh majila - avatar
1 Answer
- 1
I figured it out, but i am leaving this question so that you can solve it.
4th Oct 2020, 4:39 PM
Karan singh majila
Karan singh majila - avatar