这是我用ANSI C编写的代码.我经常遇到运行时错误:Segmentation Fault(SIGSEGV).请帮帮我.我是数据结构和C的新手.我无法检测到问题.
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node *nxt;
}node;
node * create(int n);
void display(node *head);
int main()
{
int n = 0;
node *head = NULL;
printf("Enter the number of nodes\n");
scanf("%d", &n);
head = create(n);
display(head);
return 0;
}
node * create(int n)
{
int i;
node *head = NULL;
node *temp = NULL;
node *p = NULL;
for (i = 0; i < n; i++)
{
temp = (node *)malloc(sizeof(node));
printf("\nEnter …Run Code Online (Sandbox Code Playgroud)