文件读写--读
#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);
}