程序的读取操作为什么总是有错误
为什么这个程序运行时候这两个函数,我觉得读取函数总是出错。显示信息为: int save()
{
int i;
FILE *fp;
if((fp=fopen("D:\\people_dat","ab+"))==NULL)
{
printf("cannot open file\n");
exit(1);
}
else
{
for(i=0;i<m;i++)
fprintf(fp,"%s",peo[m].name);
fprintf(fp,"%d",peo[m].year);
fprintf(fp,"%d",peo[m].month);
fprintf(fp,"%d",peo[m].in);
fprintf(fp,"%d",peo[m].out);
}
fclose(fp);
m++;
return 0;
}
int Read()
{
FILE *fp;
int i=0,m=0;
fp=fopen("D:\\people_dat","ab+");
if(fp==NULL)
{printf("File open error!\n");
exit(1);
}
else
{
do{
fscanf(fp,"%s",peo[i].name);
fscanf(fp,"%d",peo[i].year);
fscanf(fp,"%d",peo[i].month);
fscanf(fp,"%d",peo[i].in);
fscanf(fp,"%d",peo[i].out);
m++;i++;
}while(feof(fp)!=0);
}
fclose(fp);
return 0;
}