#include
#include
#define len sizeof(struct student)
struct student
{
long num;
char cla[20];
char name[20];
float score;
struct student *next;
};
void main()
{
int n,w,i,c,m,y;
n=0;
void max(struct student *head);
int revise(struct student *head);
void delet(struct student *head);
printf("为了后续操作请先进行信息录入\n");
printf("请先按照学号\t班级\t姓名\t成绩\t的顺序进行录入\n");
struct student *head;
struct student *p1,*p2,*h;
p1=(struct student *)malloc(len);
scanf("%ld %f",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{
n++;
if(n==1)head=p1;
else
p2=p1;
p2->next=p1;
p1=(struct student *)malloc(len);
scanf("%ld %s %s %f",&p1->num,&p1->cla,&p1->name,&p1->score);
}
p2->next=NULL;
printf("请选择要进行的操作 按数字结束\n");
printf("1.对成绩进行排序输出并进行相关成绩查询\t2.要在特定地方添加信息\t3.要删除特定地方的信息\t4.对某一个同学的信息进行查询");
scanf("%d",&c);
switch(c)
{
case 1:max(head);
for(;head!=NULL;head=head->next)
printf("%ld %s %s %f",head->num,head->name,head->score);
break;
case 2:printf("要对第几位同学的信息进行修改\n");
scanf("%d",&m);
revise(head);
for(;head!=NULL;head=head->next)
printf("%ld %s %s %f",head->num,head->name,head->score);
break;
case 3: printf("要对第几位同学的信息进行删除\n");
scanf("%d",&y);
delet(head);
for(;head!=NULL;head=head->next)
printf("%ld %s %s %f",head->num,head->cla,head->name,head->score);
break;
case 4:printf("请输入要查询的学号:\n");
scanf("%d",&w);
h=head;
for(i=0;i {
if(h->num==w)
{printf("%ld %f",h->num,h->score);}
h=h->next;}
}
}
void max(struct student *a)
{
struct student *p,*w,*m;
p=(struct student *)malloc(len);
p->next=a;
for(w=a;w!=NULL;w=w->next)
{
for(;p!=NULL;p=p->next)
{
if(p->next>p->next->next)
{w=p->next;p->next=p->next->next;p->next->next=w;}
}}
int revise(struct studnet *a)
{ struct student *p;
int i;
printf("要加入的信息\n");
p=(struct student *)malloc(len);
scanf("%ld %s %s %f",&p->num,&p->cla,&p->name,&p->score);
for(i=1;i<m;i++)
{a=a->next;}
p->next=a->next;
a->next=p;
return (student *a);
}
void delet(struct student *a)
{
struct student *p;
int i;
p=(struct student *)malloc(len);
for(i=1;i {a=a->next;}
p=a->next;a->next=a->next->next;
free(p);
}
哪里不清楚?这就是一个链表啊,你说的函数和主函数分不清是什么意思?
error C2601: 'revise' : local function definitions are illegal
: error C2601: 'delet' : local function definitions are illegal
: fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
这是运行结果
你函数的定义,需要放在与 main 同级的地方。如:
void main()
{
......
}
int revise(struct studnet *a)
{
struct student *p;
int i;
printf("要加入的信息\n");
p=(struct student *)malloc(len);
scanf("%ld %s %s %f",&p->num,&p->cla,&p->name,&p->score);
for(i=1;i<m;i++)
{a=a->next;}
p->next=a->next;
a->next=p;
return (student *a);
}
函数的声明,最好是放在 main() 函数外,如:
void max(struct student *head);
int revise(struct student *head);
void delet(struct student *head);
void main()
{
......
}
你的函数没有申明,需要在main函数的前面对max、revise、delet进行申明,否则主函数无法调用这几个函数的。至于如何申明,你应该会吧。
如果你的函数需要在主函数中调用,那么可以直接把这个函数放到主函数的前面,这样就不需要声明了,要不然,就需要先声明一下在调用。
代码版本有点乱了,个人建议void max(struct student *head); int revise(struct student *head); void delet(struct student *head);
可以放在main函数 外进行定义。这样也方便自己修改
执行 cl.exe 时出错.
这根本就没有链接起来,谈不上运行。
代码都不对。
函数的定义放在main的外面。你这样写是很老的C语言的写法,现在都不支持了。
先定义结构体,在定义使用结构体的函数,然后才是main函数