为啥这段代码一直通不过呀,要崩溃了,求指教,万分感谢!
```c
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct LNode
{
int data; //建了一个整型数据域
struct LNode *next; //指针域
}LinkList;
LinkList *p,*q,*head;
LinkList *build(){
head = (LinkList *)malloc(sizeof(LinkList));
head->data = 0;
head->next = NULL;
int w = 1;
int i = 0;
char ch;
while (w)
{
printf("开始输入第%d个数据\n",++i);
p=(LinkList *)malloc(sizeof(LinkList));
p->next = head->next;
head->next = p;
scanf("%d",&p->data); //输入该节点的数据域内容
printf("是否继续呢?(y/n)");
scanf("%c",&ch);
if(ch == 'n'){
break;
}
}
head->data = i; //头节点数据域用来记录有多少个节点
return head;
}
void display(LinkList *head){
printf("当前链表共有%d个节点\n",head->data);
q = head->next;
while (q!=NULL)
{
printf("%5d",q->data);
q = q->next;
}
printf("\n");
}
int main(){
display(build());
system("pause");
return 0;
}
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/141926869876134.png "#left")