#include <stdlib.h>
#include <stdio.h>
typedef struct student
{
char name[100];
int num;
int score;
}STUDENT;
STUDENT stu[ ]={"zhangsan",01,90,"lisi",02,95,"wangwu",03,95};
void Wf()
{
FILE *fp;
fp = fopen("stu.txt","wb");
int i;
for(i=0;i<3;i++)
{
fseek(fp,sizeof(STUDENT)*i,SEEK_SET);
fwrite(&stu[i],sizeof(STUDENT),1,fp);
}
fclose(fp);
}
void Rf()
{
STUDENT temp[3];
FILE *fp;
fp = fopen("stu.txt","rb");
int i;
for(i=0;i<3;i++)
{
fseek(fp,sizeof(STUDENT)*i,SEEK_SET);
fread(&temp[i],sizeof(STUDENT),1,fp);
}
fclose(fp);
}
void main()
{
Wf();
Rf();
system("pause");
}