麻烦看一下哪里错了,谢谢

zhuangyiyou 2011-05-19 10:36:04
#include<stdio.h>
#include<stdlib.h>
struct student{
int age;
struct student *next;
};

void main()
{
void disp(struct student *head);
struct student *list(){
int age1;
struct student *head,*pnew,*tail;
head=(struct student *)malloc(sizeof(struct student));
if(head==NULL)
{
printf("error");
return;
}
head->next=NULL;
tail=head;
while(age1!=0)
{

printf("input age=");
scanf("%d\n",&age1);
pnew=(struct student *)malloc(sizeof(struct student));
pnew=tail->next;
pnew->age=age1;
pnew->next=NULL;
tail=pnew;
}
}
disp(head);
}
void disp(struct student *head)
{
struct student *p=head;
while(p!=NULL)
{
printf("%d",p->age);
p=p->next;
}
}
...全文
101 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwwypy 2011-05-20
  • 打赏
  • 举报
回复
不太清楚!等待解答。
金刚葫芦娃 2011-05-20
  • 打赏
  • 举报
回复

又是链表?
screwzm 2011-05-20
  • 打赏
  • 举报
回复
c语言不允许函数嵌套,把函数的声明和定义都放主函数外面吧!
screwzm 2011-05-20
  • 打赏
  • 举报
回复
c语言不允许函数嵌套,把函数的声明可定义都放主函数外面吧!
AnYidan 2011-05-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wesleyluo 的回复:]
你的代码有很多问题,首先,main函数里面还包含了一个函数list(),你要把它拿到外面来;
然后把disp()与list()的函数声明都写到mian函数的外面去,要在main之前;
你先改了这些再说吧.
[/Quote]
++

代码注意缩进,添加必要的注释
陈思有 2011-05-19
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<stdlib.h>
struct student{
int age;
struct student *next;
};

void main()
{
void disp(struct student *head);
/*在这里删掉了一句*/
int age1;
struct student *head,*pnew,*tail;
head=(struct student *)malloc(sizeof(struct student));
if(head==NULL)
{
printf("error");
return;
}
head->next=NULL;
tail=head;
while(age1!=0)
{

printf("input age=");
scanf("%d",&age1); /*去掉这里面的\n*/
pnew=(struct student *)malloc(sizeof(struct student));
tail->next=pnew; /*这里写反了,应该是前面的next指向后面的节点*/
pnew->age=age1;
pnew->next=NULL;
tail=pnew;
}

disp(head);
}
void disp(struct student *head)
{
struct student *p=head->next;/*你并没有往第一个节点输入数据,而是存放指向有数据的第一个节点的指针*/
while(p!=NULL)
{
printf("%d ",p->age);
p=p->next;
}
}
wesleyluo 2011-05-19
  • 打赏
  • 举报
回复
你的代码有很多问题,首先,main函数里面还包含了一个函数list(),你要把它拿到外面来;
然后把disp()与list()的函数声明都写到mian函数的外面去,要在main之前;
你先改了这些再说吧.
TiannaiTNDSC 2011-05-19
  • 打赏
  • 举报
回复
你代码有点乱怎么函数中还有声明?

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧