S
sugaray
hi, the problem i'm having here is that after i've written
10 integers to a disk file, the reading process always output
one more integer than was in the file.
===========snippet for write ===========
int i;
FILE *fp;
fp=fopen("number","a+b");
for(i=0;i<10;++i)
fwrite(&i,sizeof(int),1,fp);
fclose(fp);
========== snippet for read ===========
int i;
FILE *fp;
fp=fopen("number","rb");
while(!feof(fp)){
fread(&i,sizeof(int),1,fp);
printf("%d\n",i);
};
fclose(fp);
=======================================
thanx for your help !
10 integers to a disk file, the reading process always output
one more integer than was in the file.
===========snippet for write ===========
int i;
FILE *fp;
fp=fopen("number","a+b");
for(i=0;i<10;++i)
fwrite(&i,sizeof(int),1,fp);
fclose(fp);
========== snippet for read ===========
int i;
FILE *fp;
fp=fopen("number","rb");
while(!feof(fp)){
fread(&i,sizeof(int),1,fp);
printf("%d\n",i);
};
fclose(fp);
=======================================
thanx for your help !