Can anyone please point me in the direction of a tutorial on parsing a binary file and extracting data. I want to search for file headers in Hex and export the files.

Thanks

C or C++?

C++ Binary File I/O - Basically using ifstream/ofstream with special initalization parameters and using ::write and ::read to do file i/o instead of the stream operators (<< and >>).

C Binary File I/O - Using fopen(), but using fread() and fwrite() instead of fputs() and fgets() to read files.

Hope this helps

you have to know the format of the files before you can parse them. There normally is nothing in the file that says "I'm a header record". You have to know that bytes 0 to ??? is the header record, if one even exists in the file. Evey binary file is different, there is no standard way to write or read them other than how to use stream.write() and stream.read() functions. And those functions are completly ignorent of what it is reading or writing. That's all up to the programmer.

you have to know the format of the files before you can parse them. There normally is nothing in the file that says "I'm a header record". You have to know that bytes 0 to ??? is the header record, if one even exists in the file. Evey binary file is different, there is no standard way to write or read them other than how to use stream.write() and stream.read() functions. And those functions are completly ignorent of what it is reading or writing. That's all up to the programmer.

I forgot to mention that. If you want to parse any kind of binary file, you'll need documentation to know which order the variables have been stored in the file. For example, this guide documents parsing a WAV sound file.

Hope this helps

This article has been dead for over six months. Start a new discussion instead.