|
From: Sam <sch...@ho...> - 2001-03-18 02:36:50
|
Thanks for all the suggestions. I'll try them out...
Sam
----- Original Message -----=20
From: Ioannis Vranos=20
To: dev...@li...=20
Sent: Saturday, March 17, 2001 3:25 PM
Subject: RE: [Dev-C++] feof question
You can also use :
=20
do
{=20
/* ... */
}while(!feof(filePtr));
=20
In this way you gain one less check for end of file (where performance =
is important).
=20
=20
About the second read of the "same data" at the end:
=20
This happens because the end of file is true only after a failed =
attempt (because the end of file has been already reached and it has no =
more to read). That means it doesn't read the data for the second time, =
but you have a failed attempt to read more data.
As for the counter you can either decrease it by one after the loop =
or initialize it with -1.
=20
=20
Ioannis
=20
* Ioannis Vranos
* Programming pages: http://members.nbci.com/noicys
* Alternative URL: http://run.to/noicys
-----Original Message-----
From: dev...@li... =
[mailto:dev...@li...]On Behalf Of Sam
Sent: Saturday, March 17, 2001 8:01 PM
To: dev...@li...
Subject: [Dev-C++] feof question
I'm trying to read through a file using the following statement:
while(!feof(filePtr)
{
fread(&phone, sizeof(struct record), 1, filePtr);
printf("%d%s", int, name);
count++;
}
The problem is that it reads the last record twice and increments =
the count one more time than needed. Could someone explain why this =
happens and how to avoid it using the feof function? Thanks.
Sam
|