文件读写--读
#include <stdio.h>#include <string.h>
main()
{FILE *fp1;
int i;
struct stu
{
int num;
char name[15];
float score[2];
}student;
if ((fp1=fopen(file_name,"rb"))==NULL)
{
printf("cannot open file");
exit(0);
}
printf("output from file:\n");
while(!feof(fp1))
{fread(&student,sizeof(student),1,fp1);
printf("%-10d%-20s%-10.2f%-10.2f\n",student.num,student.name,
student.score[0],student.score[1]);
}
fclose(fp1);
}
搜索更多相关的解决方案:
文件
----------------解决方案--------------------------------------------------------
应该在头文件中加入
#include <stdlib.h>
----------------解决方案--------------------------------------------------------