I am trying to create a list of 10 Nodes and assigning with the values 1 to 10 and printing them. I tried it with the following code, but I am ending up with segmentation fault.
I am very new to Linked Lists in C.
#include<stdio.h>
typedef struct Node
{
int data;
struct Node *next;
}Node_Struct;
int main(void)
{
int i =0;
Node_Struct* Node = NULL;
Node = (Node_Struct*)malloc(sizeof(Node_Struct));
for (i = 1; i<=10; i++){
Node->data = i;
Node = Node->next;
}
for (i = 1; i<=10; i++){
printf("\n Node->data:%d",Node->data);
Node = Node->next;
}
return 0;
}