#include<stdio.h>
struct student
{
char name[20];
int num;
char sex;
int age;
float score;
}
main()
{
struct student stud;
FILE *fp;
int i=2;
//从文件头向后移动两组数据,就是指向第三个学生的数据
//变量i将在后面的fseek()函数中
if((fp=fopen("stud.dat","rb"))==NULL)
{
printf("can't open file stud.dat\n");
exit(1);
}
fseek(fp,i*sizeof(struct student),0);
if(fread(&stud,sizeof(struct student),1,fp)==1)
printf("%d,%s,%d,%c,%f",stud.num,stud.name,stud.age,stud.sex,stud.score);
fclose(fp);
}
struct student
{
}
main()
{
}