Jump to content
  • Advertisement


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


Problems with I/O

This topic is 5964 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 need to be able to save stuff from my terrain editor and basically thi is what it does: use fprintf to put out header info, then I want to output a long sequence of short integers for heightmap data, followed by a long sequence of BYTEs. However if you use fprintf to put out shorts, you have to put a space or newline between them. I tried using fwrite to send out the data on a bit by bit copy to the file but that didn''t work. For the BYTEs I tried to use fputc, but when you put certain characters it screws things up trying to read them again. I basically want a mixture of fprintf/fscanf for bits that are human readable i.e map size etc, and a load of bytes for other stuff. What''as the best way? If you want to discuss specifics, I have a 2d array of shorts called heights, 2d array of bytes called groundtypes and header variables height & width which need to go in the file like: Width: 1234 Height: 1234 before the rest of the stuff. John 3:16

Share this post

Link to post
Share on other sites
Memory-mapped files are amazingly good for binary file i/o if you don''t mind Win32 code.


If you want to stay portable, then fwrite or ostream opened for binary access is the way to go. If you use fwrite properly, you won''t have any troubles. Perhaps you can elaborate on "that didn''t work" bit.

Come to #directxdev IRC channel on AfterNET

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!