一个链表问题,弹出许多非法定义错误
将如表21.1所示的学生信息建立成一个按学号升序有序的链表,每个节点包括学号、姓名、性别、年龄。统计链表中年龄小于20的学生个体数并将对应的学生信息(包括学号、姓名、性别、年龄)输出代码如下:
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
void main()
{
struct student
{
int id;
char name[10];
char x;
int age;
struct student *next;
};
struct student *head,*tail;
void lianbiao(struct student *stu)
{//第16行
stu=(struct student *)malloc(sizeof(struct student));
head=tail=stu;
stu->next=NULL;
}
void jialianbiao(int idd,char *namee,char xx,int agee)
{//22行
struct student *ss=(struct student *)malloc(sizeof(struce student));
ss->id=idd
strcpy(ss->name,namee);
ss->x=xx;
ss->age=agee;
tail->next=ss;
ss->next=NULL;
tail=ss;
}
void tlianbiao()
{//33行
struct student *now;
now=head->next;
while(now!=NULL)
{
if(now->age<20)
printf("%5d%5s%5c%5d\n",now->id,now->name,now->x,now->age);
now=now->next;
}
}
void destroy()
{//44行
struct student *now;
now=head;
while(now!=NULL)
{
head=now->next;
free(now);
now=head;
}
}
int main()
{//55行
struct student *stu;
liaobiao(stu);
jialianbiao(305001,"Zhang",'M',18);
jialianbiao(305002,"Wang",'F',20);
jialianbiao(305003,"Li",'F',19);
jialianbiao(305004,"Zhao",'M',21);
printf("学号 姓名 性别 年龄\n");
tlianbiao();
destroy();
return 0;
}
}
有如下错误
C:\Users\Administrator\Desktop\新建文件夹\链表.cpp(16) : error C2601: 'lianbiao' : local function definitions are illegal
C:\Users\Administrator\Desktop\新建文件夹\链表.cpp(22) : error C2601: 'jialianbiao' : local function definitions are illegal
C:\Users\Administrator\Desktop\新建文件夹\链表.cpp(33) : error C2601: 'tlianbiao' : local function definitions are illegal
C:\Users\Administrator\Desktop\新建文件夹\链表.cpp(44) : error C2601: 'destroy' : local function definitions are illegal
C:\Users\Administrator\Desktop\新建文件夹\链表.cpp(55) : error C2556: 'int __cdecl main(void)' : overloaded function differs only by return type from 'void __cdecl main(void)'
C:\Users\Administrator\Desktop\新建文件夹\链表.cpp(4) : see declaration of 'main'
C:\Users\Administrator\Desktop\新建文件夹\链表.cpp(55) : error C2371: 'main' : redefinition; different basic types
C:\Users\Administrator\Desktop\新建文件夹\链表.cpp(4) : see declaration of 'main'
C:\Users\Administrator\Desktop\新建文件夹\链表.cpp(55) : error C2601: 'main' : local function definitions are illegal
执行 cl.exe 时出错.
为什么错了?明明定义没啥问题啊?