#include "stdio.h"
#include "stdlib.h"
typedef struct {
char stu_ID[14];
char stu_Name[4];
char stu_Major[10];
int stu_Score;
}STU;
int main()
{
FILE *fp;
STU obj[101];
int index = 1, n, i = 0;
//Data_In_B(fp, obj);
fp = fopen("cet4.dat", "rb");
while(!feof(fp))
{
fread(obj,sizeof(STU),1,fp);
printf("%s %s %s %d\n",
obj[0].stu_ID, obj[index].stu_Name, obj[0].stu_Major, obj[0].stu_Score
);
}
fclose(fp);
return 0;
}
在读取二进制文件时需要确保文件数据是以二进制方式写入的,如果以十进制方式写入的文件时无法用二进制读取方式正确读取的。
这个文件不能用二进制方式读取吧,直接普通方式读取