Jump to content
  • Advertisement
Sign in to follow this  
wforl

eof character

This topic is 3641 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im reading in some text files that i make in general editors, but when using the standard !eof() function i find that the files being read only get detected for this when made by certain apps. For example when i export from one app, the end of file gets detected and all is well. But when i export from this other partcicular app, the end of file bit doesn't get dtetced and it just runs over into ram. Can somone tell me if there is an application/text editor i can use to load in the particular files, to check if there is indeed an eof byte in the actual file. And also what the byte is? i believe its a -1?

Share this post


Link to post
Share on other sites
Advertisement
There is no 'EOF byte' -- feof() just returns a nonzero value if the file pointer in question has the end-of-file indicator set. C and C++ have an EOF macro, but this just a system-defined value that is used to indicate that the EOF condition has occured, it's not a value you get from the file itself.

Share this post


Link to post
Share on other sites
There's no such thing as an "EOF byte", at least one which is actually recognized as an EOF by the feof() function. Your interpretation of the situation is incorrect. Much more likely is that you weren't aware that the feof() function does not return true until after a read has failed. In other words, feof() returning false does not mean that there's more data to read, only that no read has failed yet.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
There's no such thing as an "EOF byte", at least one which is actually recognized as an EOF by the feof() function. Your interpretation of the situation is incorrect. Much more likely is that you weren't aware that the feof() function does not return true until after a read has failed. In other words, feof() returning false does not mean that there's more data to read, only that no read has yet failed for that reason.


Minor fix. :)

There exists a variant of the 'get' function which reads one character, but reads it as an int, returning 0 through 255 if there is an available character, and -1 if the file is at the end. This might be what you were thinking of.

Show the code that you use to read the files.

Share this post


Link to post
Share on other sites
Some systems used a real character (^Z == 0x26) for EOF. I haven't seen that used in a LONG time, though.

Most file APIs I've used lately check for EOFs by comparing the current position in the file to the length.

Share this post


Link to post
Share on other sites
well here is mt code


std::string fullLine;
std::string firstword;


while(!objFile.eof())
{
count++;
getline(objFile, fullLine);
std::stringstream line(fullLine);

line >> firstword;

//process firstline


Share this post


Link to post
Share on other sites
Quote:
Original post by maya18222
getline(objFile, fullLine);


After you execute this line, you should check whether you reached the end-of-file. If you did, then no line was read and the original contents of the string are still there. See daviangel's post for more information.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!