可以读出来,但是显示不出数据
int read()//读取文件
{
//定义文件指针,操作文件
FILE *fp;
fp=fopen("Students2.txt","r");
int i = 0,j = 0; //定义读取文件的行数
if(fp==NULL)
{
printf("文件未打开\n");
return 0;
}
while (!feof(fp))
{
fscanf(fp,"%s",stu[i].no);
fscanf(fp,"%s",stu[i].name);
fscanf(fp,"%s",stu[i].sex);
fscanf(fp,"%d",&stu[i].age);
fscanf(fp,"%s",stu[i].clname);
fscanf(fp,"%d",&stu[i].scoremath);
fscanf(fp,"%d",&stu[i].scoreEnglish);
fscanf(fp,"%d",&stu[i].scorephysics);
fscanf(fp,"%d",&stu[i].scoreprocedure);
fscanf(fp,"%d",&stu[i].scoresixiu);
fscanf(fp,"%d",&stu[i].scorezhongchuan);
i++;
}
fclose(fp);//关闭文件
FILE *Fp;
Fp=fopen("Students2.txt","rb");
if(Fp==NULL)
{
printf("文件未打开\n");
exit (0);
}
while(!feof(Fp))
{
strcpy(stu[j].no,stu[j+1].no);
strcpy(stu[j].name,stu[j+1].name);
strcpy(stu[j].sex,stu[j+1].sex);
stu[j].age=stu[j+1].age;
strcpy(stu[j].clname,stu[j+1].clname);
stu[j].scoremath=stu[j+1].scoremath;
stu[j].scoreEnglish=stu[j+1].scoreEnglish;
stu[j].scorephysics=stu[j+1].scorephysics;
stu[j].scoreprocedure=stu[j+1].scoreprocedure;
stu[j].scoresixiu=stu[j+1].scoresixiu;
stu[j].scorezhongchuan=stu[j+1].scorezhongchuan;
j++;
}
fclose(Fp);//关闭文件
}
```c
int write()//写入文件
{
FILE * fp;
int i = 0;
if ((fp = fopen("F:\\student\\Students2.txt", "w")) == NULL)
{
printf("打开文件失败");
return 0;
}
while(1)
{
fprintf(fp,"%s",stu[i].no);
fprintf(fp,"%s",stu[i].name);
fprintf(fp,"%s",stu[i].sex);
fprintf(fp,"%d",stu[i].age);
fprintf(fp,"%s",stu[i].clname);
fprintf(fp,"%d",stu[i].scoremath);
fprintf(fp,"%d",stu[i].scoreEnglish);
fprintf(fp,"%d",stu[i].scorephysics);
fprintf(fp,"%d",stu[i].scoreprocedure);
fprintf(fp,"%d",stu[i].scoresixiu);
fprintf(fp,"%d",stu[i].scorezhongchuan);
}
fclose(fp);
}