Archived

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

File input/output problems

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