为什么我输入两组数据存入,会有四组数据读出啊!应该怎么改啊??
#define N 100#include <stdio.h>
#include <stdlib.h>
struct student
{char name[20];
char reason[20];
float money;
}st[N];
main()
{FILE *fp1,*fp2;
char ch;
int i;
float f;
if((fp1=fopen("file1.txt","w"))==NULL)
{printf("\n文件file1.txt打不开!\n");
exit(0);}
i=0;
do
{printf("请输入班费信息:姓名,原因,金额");
scanf("%s%s%f",st[i].name,st[i].reason,&f);
st[i].money=f;
fwrite(&st[i],sizeof(struct student),2,fp1);
i++;
getchar();
printf("\n继续输入学生信息(y/n)?");
ch=getchar();getchar();}
while(ch=='y'||ch=='Y');
fclose(fp1);
if((fp2=fopen("file1.txt","r"))==NULL)
{printf("\n文件file1.txt打不开!\n");
exit(0);}
while(fread(&st,sizeof(struct student),1,fp2)==1)
{printf("\n姓名:%s",st->name);
printf("\n原因:%s",st->reason);
printf("\n金额:%f",st->money);}
if(!feof(fp2)) printf("\n读文件出错! \n");
fclose(fp2);}