EOF()

Hi,

I have been using EOF() and it has almost worked for me till today. I have two files which has some numbers per line separated by space characters. I used to get each and every character until the EOF is reached. I made a program to read the text file. It works for the one of the file and for the other when I run the same program the loop never ends. The text file is like 90MBin size. So it is very hard for me to check what exactly is happening in the end of the file. No matter what happens at the end, doesn't the eof only denotes a Boolean 1 when the pointer to the file reached the end of the file? How can it go on without ever finding the eof. here is what I have been using:

OpenFile1>>value;
while (!OpenFile1.eof())// Till end of each record
{
OpenFile1>>value;
}

Since it worked for one file and does not work to reach the end for the other there is something in the other text file that I an not sure of. Can anybody please explain what are the possibilities that are causing the failure of eof.

Thanks
Ashish
chemas-microsoft-comSurprisefficeSurpriseffice" />>
>

[1961 byte] By [aagar_2003] at [2007-12-16]
# 1
wrote in message news:f95f561d-6aa8-44a4-86c5-1a5926e1dd81_WBRev2_@discussions.microsoft.com
> I have been using EOF() and it has almost worked for me till today. I
> have two files which has some numbers per line separated by space > characters. I used to get each and every character until the EOF is
> reached. I made a program to read the text file. It works for the one
> of the file and for the other when I run the same program the loop
> never ends. The text file is like 90MBin size. So it is very hard for
> me to check what exactly is happening in the end of the file. No
> matter what happens at the end, doesn't the eof only denotes a
> Boolean 1 when the pointer to the file reached the end of the file?
> How can it go on without ever finding the eof. here is what I have
> been using:
>
> OpenFile1>>value;
> while (!OpenFile1.eof()) // Till end of each record
> {
> OpenFile1>>value;
> }

Try changing it to OpenFile1>>value; while (OpenFile1) { OpenFile1>>value; } What I think happens is somewhere in the middle of the file you have a value that cannot be parsed as a valid number. At this point, the stream sets failbit (you can check with OpenFile1.fail() ), which means that all subsequent operations will also fail. Thus, no progress is being made and end-of-file is never reached. (bool)(OpenFile1) checks all the status bits - badbit, failbit, eofbit. It is true when no bits are set, false when at least one bit is set. -- With best wishes, Igor Tandetnik

MVPUser at 2007-8-21 > top of Msdn Tech,Visual C++,Visual C++ General...