binary file i/o questions
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
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
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.
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
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
// CHRIS [win32mfc]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement