好几处错误,函数体里也有错误:
#include <stdio.h>
#include <stdlib.h>
/***********Begin***********/
struct STUDENT{
long num;
char name[13];
float score[4],total,average;
};
/***********End*************/
void Input(struct STUDENT *stud, int n);
void Print(struct STUDENT *stud, int n);
void TotalAndAverage(struct STUDENT *stud, int n);
int main()
{
int n;
/***********Begin***********/
printf("Input n(n<=30):");
scanf("%d",&n);
//scanf("%d",n); 修改
struct STUDENT a[31],*stud;
// stud=(struct STUDENT *)malloc(n,sizeof(struct STUDENT));
stud=a;
Input(stud, n); //修改
//void Input(struct STUDENT *stud, int n);
//stud=&a[0];
TotalAndAverage(stud, n);//修改
//void TotalAndAverage(struct STUDENT *stud, int n);
//stud=&a[0];
Print(stud, n); //修改
//void Print(struct STUDENT *stud, int n);
/***********End*************/
return 0;
}
void Input(struct STUDENT *stud, int n)
{
/***********Begin***********/
for(int i=0;i<n;i++){
scanf("%ld", &(*stud).num);
scanf("%s", (*stud).name); //&(*stud).name[13]);修改
for(int j=0;j<4;j++){
scanf("%f", &(*stud).score[j]);
}
stud++;
}
/***********End*************/
}
void Print(struct STUDENT *stud, int n)
{
printf("%8s%12s%10s%10s%10s%10s%10s%10s\n","NO.","Name","Computer","English","Math","Music","Total","Average");
for(int i=0;i<n;i++)
{
printf("%8ld",(*stud).num);
printf("%12s",(*stud).name); //(*stud).name[13]); 修改
for(int j=0;j<4;j++)
{
printf("%10.0f",(*stud).score[j]);
}
printf("%10.0f",(*stud).total);
printf("%10.0f\n",(*stud).average);
stud++;
}
}
void TotalAndAverage(struct STUDENT *stud, int n)
{
/***********Begin***********/
float x=0;
for(int i=0;i<n;i++){
x=0;
for(int j=0;j<4;j++){
x=(*stud).score[j]+x;
}
(*stud).total=x;
x=x/4.0; //修改
(*stud).average=x;
stud++;
}
/***********End*************/
}