Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Cat_B

feof (end of file) not recognized.

This topic is 5601 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

Hi, I wrote a random access data file using fwrite. I then read it doing while(!feof){} but it doesn''t see the feof and keeps going. Do I have to write a special feof character? I know its ctl-z for windows, but how do I write this at the end of a file? thanx (I''m using C, not c++ and its a console program)

Share this post


Link to post
Share on other sites
Advertisement
feof is a function. Your code is testing whether its address is not 0. Which it will never be. You need to actually call the function : while( !feof( fp ) ) { /* ... */ } where fp if your file pointer.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
Yes, soory, that was an ommision in my post, but not my code.

my code is
while (!feof(cfPtr)){
fread(&dx,sizeof(dx),1,cfPtr);
fseek(cfPtr,sizeof(dx),SEEK_CUR);
fread(&dy,sizeof(dy),1,cfPtr);
printf("dx: %d /t dy: %d \n", dx, dy);
fseek(cfPtr,sizeof(dy),SEEK_CUR);
}

Share this post


Link to post
Share on other sites
You don''t need to seek after a read. You''re probably seeking past the end of the file. I don''t know what feof returns in that case.

Share this post


Link to post
Share on other sites

  • 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!