|
-
May 17th, 2010, 12:37 AM
#8
Re: learning binary files.
Here's an example of where using a header would be useful.
Code:
struct FileHeader
{
unsigned long FileID; // The type of file so you can recognize if it's valid data
unsigned short HighVersion; // The high version
unsigned short LowVersion; // Low Version
unsigned long OffsetToData; // Offset in file to data entries, this allows
// other "tag" headers to follow file header
// such as author tags/etc...
unsigned long DataEntryCount; // The number of data entries in the file
};
struct ContactInfo // This is the type of "data entry"
{
char FirstName[16];
char LastName[24];
unsigned short BirthMonth; // 1 = January, 12 = December
unsigned char BirthDay;
unsigned short BirthYear;
char AddressLine1[64];
char AddressLine2[32];
char City[32];
char State[24];
char ZipCode[5];
char PhoneNumber[10];
char EmailAddress[40];
};
// set the data members in the header, write the header (if any other tags, write them), write the data entries at the correct offset
// read the data members into a header variable, (if any other tags, read them), seek to the data enty offset, read data entries
 Originally Posted by ehoi
I was talking about binary files in general. I thought using headers such was a common convention ( " http://www.magicdb.org/filedesign.html " for an example).
If I wanted to use a header style of saving information i would need to understand how they work. So, in that respect, I guess i am asking about .bmp files too. (to understand how to go about doing it, or even make sense of someone elses files.)
Yes, it IS a common convention to use headers for binary files. Almost every binary data file needs a description of what it contains to SOME EXTENT. Like a count of data entries, etc... There are exceptions, few, but there are. One example would be that every input file for a given program is atleast supposed to be GUARANTEED to contain data that is always in the same format, ie... pixel data that is ALWAYS at the same resolution and color depth. BITMAPS on the other hand, are NOT GUARANTEED to be the same resolution/color depth/etc... so header data is NECESSARY to describe what type of data resides in the file.
Last edited by CppCoder2010; May 17th, 2010 at 12:43 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|