By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

any other way to recognize end of file.....

P: 6
hi all,

i have a doubt regarding checking the condition for the endoffile in a loop

generally we were using
while(!fin.eof())

but due to some reason it was not recognizing the eof
checked out all the possible errors
but couldn trace out

is there any other way than eof
to check for end of file.................


thanks in advance..................
Aug 8 '07 #1
Share this Question
Share on Google+
4 Replies


P: 93
hi all,

i have a doubt regarding checking the condition for the endoffile in a loop

generally we were using
while(!fin.eof())

but due to some reason it was not recognizing the eof
checked out all the possible errors
but couldn trace out

is there any other way than eof
to check for end of file.................


thanks in advance..................
I think You can try with a Null character at the end. '\0'

I am not sure of this but I feel the last character in the file
may be NULL; the same technique is used by eof as well.

Regards,
Girish.
Aug 8 '07 #2

100+
P: 180
Did you try clearing the stream?
I think the stream is corrupted.

I dont know much about C but in C++ there is a flag called clear which resets all the flag of the stream used.
Something like this
Expand|Select|Wrap|Line Numbers
  1. ifstream ifs("text,txt");
  2.   if( !ifs.isopen() ) 
  3.           return -1;
  4.   while( !ifs.eof() ) 
  5.    {
  6.         //read the data 
  7.         //check if the stream is corrupted using if( ifs.isgood() ) something I'm not            //sure
  8.         ifs.clear();
  9.    }
Aug 8 '07 #3

P: 6
thanks a lot rajeev and girish ....
that answers my question.
Aug 8 '07 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
You probably need a \n as the final line of the file.
Aug 8 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.