#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define LEN sizeof(struct Student)
#define SIZE 10
struct Student{
int num;
char name[20];
float score;
int age;
}stud[SIZE];
void print(struct Student stu){
printf("学号:%d \t姓名:%s \t成绩:%f \年龄:%d ",stu.num,stu.name,stu.score,stu.age);
}
int main()
{
FILE fp;
int i;
if(!(fp = fopen("stud.dat", "rb"))){
printf("can't open file\n'");
exit(0);
}
for(i=0;i<SIZE;i+=2){
fseek(fp,iLEN,0);//移动文件位置标记,偏移于文件头
fread(&stud[i],LEN,1,fp);
print(stud[i]);
printf("\n");
}
fclose(fp);
return 0;
}