编写了genderstat()函数用于实现按性别统计学生信息,该函数可输出男性或女性的学生信息并输出男生/女生人数。但运行时编译器报错,这个该如何解决呢?
报错如下:
代码如下:
void genderstat() //该函数用于实现按性别统计
{
int i,count=0; //count变量用于计数
char gender,c;
FILE * fp; //定义一个文件指针fp
read(); //读取students文本文件
printf("请输入要统计的性别(m/f):\n");
scanf("%c",&gender);
do{
if(gender == 'm')
{
printf("|#学号\t\t姓名\t性别\t年龄\t数学分析\t高等代数\t程序设计\t大学英语\tGPA\t#|\n");
for(i = 0;i < n; i++){
if(strcmp(st[i].gender,'m') == 0) //比较字符串
{
count++;
printf(" %d ", st[i].id);
printf(" %-s ", st[i].name);
printf(" %-s ", st[i].gender);
printf(" %d ", st[i].age);
printf("\t%d ", st[i].MathAna);
printf("\t\t%d ", st[i].LiAlg);
printf("\t\t%d ", st[i].Computer);
printf("\t\t%d ", st[i].English);
printf("\t\t%.2f \n", st[i].GPA);
}
}
printf("\n\t\t共%d名男生",count);
}
else
{
printf("|#学号\t\t姓名\t性别\t年龄\t数学分析\t高等代数\t程序设计\t大学英语\tGPA\t#|\n");
for(i = 0;i < n; i++){
if(strcmp(st[i].gender,'f') == 0) //比较字符串
{
count++;
printf(" %d ", st[i].id);
printf(" %-s ", st[i].name);
printf(" %-s ", st[i].gender);
printf(" %d ", st[i].age);
printf("\t%d ", st[i].MathAna);
printf("\t\t%d ", st[i].LiAlg);
printf("\t\t%d ", st[i].Computer);
printf("\t\t%d ", st[i].English);
printf("\t\t%.2f \n", st[i].GPA);
}
}
printf("\n\t\t共%d名女生",count);
}
printf("\n\n\t\t\t\t是否继续该操作(Y/N):"); // 提示是否继续
scanf("%c", &c);
c = getchar();
}while(c == 'Y'||c == 'y');
}