Part 2: Read from a binary file
Posted on 2003-03-19
I have a binary file whose structure is thus:
Identifier : [4 bytes]
RecordSize : [4 bytes]
Name : [null terminated string]
Address : [null terminated string]
Balance : [4 bytes]
Thanks to others, I am able to sucecssfully process the null terminated strings now. But I want to be able to copy the Identifer, RecordSize and Balance from my memory buffer and into a local variable.
I was trying memcpy, but it doesn't seem to work (because I'm stuffing up something).
The Balance field is numerical in the database that created the original data file. When I examine the data file with a Hex editor, I can see the value of this field (in Hex). However, it is stored as a little endian. Will I have to write code to accomodate the little endian storage, or will it be handled auto-magically for me?
I am starting off with a big project to learn my way through c++ - so please excuse any basic learner questions.