Creation of node:
struct Node
{
int data;
struct Node *link;
};
struct Node *head = NULL;
Append Function
int append()
{
struct Node *temp;
struct Node *p;
temp = (struct Node *)malloc(sizeof(struct Node));
printf("Enter the data");
scanf("%d", &temp->data);
if (head == NULL)
{ temp->link = NULL;
head = temp;
}
else
{
p = head;
while (p != NULL)
{
p = p->link;
}
p->link=NULL;
}
return p->data;
}
Main Function
void main()
{
int append();
int insert();
int insert_begin();
int display();
int delete ();
int del_between();
int k = 1, ch ,d;
while (k)
{
printf("
Enter choice
");
printf("1.Append
");
printf("2.In between
");
printf("3.At the beginning
");
printf("4.Display
");
printf("5.Delete
");
printf("6.Delete from between
");
printf("7.Quit
");
scanf("%d", &ch);
switch (ch)
{
case 1:
d = append();
printf("pushed %d",d);
break;
case 2:
insert();
break;
case 3:
insert_begin();
break;
case 4:
display();
break;
case 5:
delete ();
break;
case 6:
del_between();
break;
case 7:
k = 0;
break;
default:
printf("wrong choice");
}
}
}
I have been trying to append a node at the end of a linked list but as soon as I enter the data to be added Segmentation default error occurs.
Output screen
Enter choice
1.Append
2.In between
3.At the beginning
4.Display
5.Delete
6.Delete from between
7.Quit
1
Enter the data23
Segmentation fault
.........................................................................................................
What is the meaning of Segmentation fault ?How to get rid of it? Where am I going wrong?
................................................................................................................
Thanks.
question from:
https://stackoverflow.com/questions/65882918/segmentation-default 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…