动态链表问题
#include <stdio.h>#include <stdlib.h>
#define LEN sizeof(struct student)
struct student
{long num;
char name[20];
float score[3];
struct student *next;};
void main() //主函数
{struct student *stu;
struct student *shuru();
void chuli(struct student *p);
void shuchu(struct student *p);
stu=shuru();
chuli(stu);
shuchu(stu);}
struct student *shuru() //输入函数
{ struct student *head,*p1,*p2; int n;
p1=p2=(struct student*)malloc(LEN);
scanf("%ld,%s,%f,%f,%f",&p1->num,p1->name,&p1->score[0],&p1->score[1],&p1->score[2]);
head=NULL;
for(n=1;n<3;n++)
{
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
scanf("%ld,%s,%f,%f,%f",&p1->num,p1->name,&p1->score[0],&p1->score[1],&p1->score[2]);
}
p2->next=NULL; return(head);
}
struct student *p1; //全局变量
void chuli(struct student *p) //处理函数
{float a=0.0,b;
for(p;p->next!=NULL;p=p->next)
{b=(p->score[0]+p->score[1]+p->score[2])/3.0;
if(a<b) a=b,p1=p;}}
void shuchu(struct student *p) //输出函数
{for(p;p->next!=NULL;p=p->next)
{printf("%s的平均分是",p->name);
printf("%f\n",(p->score[0]+p->score[1]+p->score[2])/3.0);}
printf("最高分的学生是%s\n",p1->name);}
检测通过,但运行错误,为什么啊????我想了很久的了,哎,求救啊