Titi Anggono wrote:
> Hi all,
>
> I have problem regarding feof(). For example, I have
> two files (data1.txt and data2.txt).
> data1.txt :
> 1 2
>
> data2.txt:
> 1 2
> 1.0 2.0 3.0
> 4.0 5.0 6.0
> 7.0 8.0 9.0
>
> Here is the code that I use to read data1.txt
> ===============
> ...
> while(!feof(fp)){
> fscanf(fp,"%d %d",&n,&m)
> printf("%d %d",n,m);
> }
> .....
> ===============
>
> And for the second file
> ===============
> ...
> while(!(feof(fp)){
> fscanf(fp,"%d %d",&n,&m);
> print("%d %d",n,m)
> for(i=0;i<3;i++){
> for(j=0;j<3;j++){
> fscanf(fp,"%lf",a[i][j]);
> }
> }
> }
> ....
> =================
>
> For the first code, I get what I want. It prints
> 1 2
> But for the second code, it prints twice
> 1 2
> 1 2
> It seems while() accesses data2.txt twice.
>
> I wonder where the problem is. Thanks for any
> explanations.
>
> Cheers,
> Titi
feof() only returns a non-zero value after attempting to read past the
end of the file.
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/