另外你的main函数中,定义的//char no[7];注释掉,因为你已经定义了全局变量了。否则全局变量没有效
程序代码:
void Check_score() { FILE *f; int a; float b; char no2[7]; f = fopen("record.txt", "r+"); if (f == NULL) { printf("sorry to fail to open record.txt,exit now."); return; } printf("your previous records are:\n"); while (fscanf(f, "\n%s %3d %f", no2, &a, &b) != EOF) //我的IDE不支持%.2f { if (strcmp(no, no2) == 0) printf("\n%s %3d %.2f", no, a, b); } fclose(f); system("pause"); }