Archived

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

binary file i/o questions

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

for my map format I want to keep it simple, yet cryptic so stupid people can''t edit the file. I won''t be using any kind of compression or anything. my two questions are. 1: can I load a text file and save it as a binary file? 2: once I load a binary file, how do I actually read the data? (like sscanf() for text files) thanks, Joe JoeMont001@aol.com www.polarisoft.n3.net

Share this post


Link to post
Share on other sites
quote:

1: can I load a text file and save it as a binary file?



Yep. No reason why you shouldn''t be able to. Just load the data into an array of chars then save out that array in binary mode.

quote:

2: once I load a binary file, how do I actually read the data? (like sscanf() for text files)
thanks



I personally like to use fopen, fread, fwrite etc. They''re pretty easy to use.

----------------------------------------
Whenever I see an old lady slip and fall on a wet sidewalk, my first instinct is to laugh. But then I think, what if I was an ant and she fell on me? Then it wouldn't seem quite so funny.

Share this post


Link to post
Share on other sites
1: can I load a text file and save it as a binary file?

Yes, but if you do that it will probably be exactly the same as the original text file. Text and binary are really no different. To say a file is text is to say that it consists of basically just the ''printable'' characters. A text file is logically assumed to be a sequence of ''lines'' seperated by carriage-returns/line-feed pairs (on the PC; usually just line-feeds on *nix systems).

Possibly come up with a ''binary'' method of manipulating the file; or converting from text to a more ''binary'' format.

2: once I load a binary file, how do I actually read the data? (like sscanf() for text files)

Umm.. once you ''load a binary file'', then you have already ''read the data''.... But to read a binary file, try using the fopen(), fread(), fclose() sequence of functions.


HTH,
// CHRIS

Share this post


Link to post
Share on other sites