#include "stdio.h"
main() {
FILE *fp;
int num = 0;
float x, y, z;
fp = fopen("cj.dat", "r");
while (!feof(fp)) {
fscanf(fp, "%f,%f,%f", &x, &y, &z);
if ((x + y + z) / 3 >= 90)
num = num + 1;
}
printf("平均成绩在90分以上的学生人数:%2d人\n", num);
fclose(fp);
}
修改如下,供参考:
#include <stdio.h>
int main()
{
FILE *fp;
int num = 0;
float x, y, z;
fp = fopen("cj.dat", "r");
if (fp == NULL){ //修改
printf("file open fail!\n");
return 1;
}
while (1) { //while (!feof(fp)
if (fscanf(fp, "%f,%f,%f", &x, &y, &z) != 3) break; //修改
if ((x + y + z) / 3 >= 90)
num = num + 1;
}
fclose(fp);
printf("平均成绩在90分以上的学生人数:%2d人\n", num);
return 0;
}
无类型说明符
改成void main()
无定义fp
fopen使用方式错误