Jump to content
  • Advertisement

Archived

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

dr_slash_uh

File input/output problems

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

I been having a very hard time using integers with file input and output. Whan i store an integer in a file with a method, and retrieve it fputc(x, fp) x=getc(fp) the integer variable is not always correct, and when I save a negative integer it is never correct. Help would be greatly appreciated

Share this post


Link to post
Share on other sites
Advertisement
fputc() and getc() only work with the low-order byte of the value you pass to them, not sure if im right here but with integers the high-order byte or bit is the sign bit which may be the cause behind the errors when you use negative values with these functions as the sign bit is being ignored

Share this post


Link to post
Share on other sites
I figured out the problem the put and get function only saves 1 char that is 1byte. an integer is 2 bytes. I am sure some talented programmer knows a way to save an integer somehow

Thanks

Share this post


Link to post
Share on other sites
Thanks alot. It took me 3 hours but I figured it out myself. after a lot of painstaking experimentation. First I used oftream to write to the disk. Than i seperated any variable I stored on disk with a space. Now I have to find a way to store it in binary.

God Bless

Robert

Share this post


Link to post
Share on other sites
quote:
I am sure some talented programmer knows a way to save an integer somehow

No this have been a problem for computer scientist all over the world, if you really found a solution (which i doubt) please put it in the public domain. Even though a discovery like this is probably worth a lot of $$$...

[edited by - nafdahlix on November 10, 2003 7:56:05 PM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!