Advertisement

Got a question about binary files

Started by July 31, 2000 02:16 PM
4 comments, last by Neo_Matrix 24 years, 4 months ago
Hey all. I just got a question about binary files. I never really read exactly what a binary file is. I know you would want to write to one to keep data a secret so the user can''t go in and change his stats or something important. But how is a variable stored in it. I know you use the ios::bin but what happens to a variable. How does it convert? And then how does it come out of binary when reading in the file? Thanks, I just always wondered about this cause I plan on using binary files to save games. Thanks guys. Please point me to any articles/tutorials on this. Neo_Matrix
Neo_Matrix
Binary files are stored using structures.
For example:

struct FILE
{
char name[50];
int something;
char whatever;

} SaveGame;

Then you would write and read it to a file.
There''s no point in explaining more about this since there''s an article right here.



The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction
Advertisement
You don''t have to use structures. Binary files are just a series of binary digits (bits). On most PC''s, 8 bits becomes a byte, 16 bits is a word (short in C), 32 bits is a double word (long/int in C).
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
All files are binary!!!
If you open a file in binary mode, and you write variables to it, they''re stored as they are in memory.
There''s also the posibility to open a file in text mode. Then e.g. numbers are not stored binary but as their ASCII digits.

GA
Visit our homepage: www.rarebyte.de.stGA
I think that the binary/text options in most file managing functions refer to the translation of linefeeds (and maybe something else) the idea is that in a text file in a windows system, if you write a new line character, it gets translated to the return/new line combination; (two char).

You know, I never wanted to be a programmer...

Alexandre Moura
You're right ga, all files on computers are binary, but some OSs (Windows for example) make a small distinction between textfiles and binary files.

>> Then e.g. numbers are not stored binary but as their ASCII digits. <<

In text-mode files, all the data is still binary. It's how it's interpreted that's matter. ASCII digits are (binary) numbers too.

Edited by - Muzzafarath on August 2, 2000 5:16:53 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall

This topic is closed to new replies.

Advertisement