C语言链表 运行出错

来源:百度知道 编辑:UC知道 时间:2024/09/21 02:43:09
这个程序运行不了,请高手指教?

struct node{
int date;
struct node *next;};

create()
{
struct node *head,*tail,*p;
int x;
head=tail=NULL;
printf("/n shu ru:");
scanf("%d",&x);
while(x!=0)
{p=(struct node *)malloc(sizeof(struct node));
p->date=x;
p->next=NULL;
if(head==NULL) tail=head=p;
else tail->next=p;
tail=p;
scanf("%d",&x);}
return(head);
}

output(struct node *a )
{
do
printf("%d",a->date);
a=a->next;
while(a->next!=NULL);
}

main()
{
struct node *q;
q=create();
output(q);
}

给,已经编译运行通过了,
具体改的地方请看注释:

struct node{
int date;
struct node *next;};

struct node * create() ////////Error1:需要将函数返回值类型指定为struct node * 型
{
struct node *head,*tail,*p;
int x;
head=tail=NULL;
printf("\n shu ru:");////////Error2:这儿应该是\n,不是/n
scanf("%d",&x);
while(x!=0)
{p=(struct node *)malloc(sizeof(struct node));
p->date=x;
p->next=NULL;
if(head==NULL) tail=head=p;
else tail->next=p;
tail=p;
scanf("%d",&x);}
return(head);
}

output(struct node *a )
{
do{//////// Error3:这儿少了一个花括号
printf("%d",a->date);
a=a->next;}//////// Error4:这儿少了一个花括号
while(a->next!=NULL);
}

main()
{
struct node *q;
q=create();
output(q);
}