求助C语言 建立一个单向链表,链表中的每个结点有一个int类型的数据域,输入0时标志链表建立过程结束。

如题所述

你好!!!
修改如下:
#include
"stdafx.h"
#include
<stdio.h>
#include
<math.h>
#include
<malloc.h>
#include
<stdlib.h>
struct
node
{
int
data;
struct
node
*next;
};
void
main()
{
struct
node
*head,*tail,*p;
int
x;
head=tail=null;
printf("\
请输入一个整数");
scanf("%d",&x);
while(
x
!=
0
)
{
p=(struct
node
*)malloc(sizeof(struct
node));
p->data=x;
p->next=null;
if
(head
==
null)
head
=
tail
=p
;
else
tail
->next=p;
tail
=p;
printf("请输入一个整数:");
scanf("%d",&x);
}
//return(head);主函数怎么会有返回值呢,有的话也是return
0
}
我只是修改错误,至于出现的目的我不是很清楚。
要是有我们疑惑我们在交流!!
温馨提示:答案为网友推荐,仅供参考
相似回答