请大家运行一下这个程序 他说我Information这个结构体未识别 这是为什么
万分感激!!
#include <stdio.h>
#include <stdlib.h>
#define N 50
#define MAX 4
struct Information{
char num[N];
char name[N];
double Chinese;
double Math;
double English;
double average;
double sum;
}information[MAX];
int mycmp(const void *a, const void *b){
return (*(Information *)a)->average > (*(Information *)b)->average ? 1 : -1;
}
int main()
{
int i;
for(i = 0; i < 4; i++){
information[i].sum = 0.0;
printf("学号: ");
scanf("%s*c", information[i].num);
printf("\n姓名: ");
scanf("%s*c", information[i].name);
printf("\n语文成绩: ");
scanf("%lf", &information[i].Chinese);
information[i].sum += information[i].Chinese;
printf("\n数学成绩: ");
scanf("%lf", &information[i].Math);
information[i].sum += information[i].Math;
printf("\n英语成绩: ");
scanf("%lf", &information[i].English);
information[i].sum += information[i].English;
information[i].average = information[i].sum/4;
}
qsort(information, 4, sizeof(information[0]), mycmp);
for(i = 0; i < 4; i++){
printf("....平均成绩第%d名...\n", i+1);
printf("学号: %s\n", information[i].num);
printf("姓名: %s\n", information[i].name);
printf("语文成绩: %.2lf\n", information[i].Chinese);
printf("数学成绩: %.2lf\n", information[i].Math);
printf("英语成绩: %.2lf\n", information[i].English);
printf("平均成绩: %.2lf\n", information[i].average);
}
return 0;
}
那这几行语句应加在哪里。。
追答居然这么问.......直接给你改了吧
return (*(Information *)a)->average > (*(Information *)b)->average ? 1 : -1;
===>
return ( ((struct Information *)a)->average > ((struct Information *)b)->average ) ? 1: -1;