(求助)有关文件内容处理的问题
struct student{
char name[10];
int num;
char sex[5];
int age;
int chinese;
int math;
int english;
int computer;
int total;
float average;
}s[5]; 这是我定义的结构体.
--------------------------------
我用以下函数输入了5个学生的信息,并存入了一个文件内.
void save()
{
int i;
char file[15];
FILE *fp;
printf("please input a name of the file you want to save: ");
scanf("%s",file);
printf("\nplease input SIZE students informations:\n");
printf("the information include:Name Number Sex Age Chinese Math English Computer\n");
for(i=0;i<SIZE;i++)
{ scanf("%s%d%s%d%d%d%d%d",s[i].name,&s[i].num,s[i].sex,&s[i].age,&s[i].chinese,&s[i].math,&s[i].english,&s[i].computer);
s[i].total=s[i].chinese+s[i].math+s[i].english+s[i].computer;
s[i].average=(float)s[i].total/4;
}
if((fp=fopen(file,"wb"))==NULL)
{
printf("cannot open file\n");
return;
}
for(i=0;i<SIZE;i++)
if(fwrite(&s[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
请问我要怎样修改文件里面任意的学生信息??
高手见笑了,帮个忙,谢了!