D
DeveloperDave
Ok, so I'm sure this is a common task, but I have been unable to find
a good algorithm for it. Currently I just have a horrible looking
nestled 'if' blocks, so hopefully someone can help me out with a more
elegant solution.
I have a large binary file. Essentially the binary file contains 1 or
more paragraphs. Each paragraph starts with a four byte sequence:
0x4F 0x67 0x67 0x53
In my C++ application I open a fstream to the file in binary mode. I
want to iterate through the file, and pass each paragraph into a new
class which will know what to do with it.
I have been using a read() to copy a chunk of data into a buffer, then
iterate through the buffer checking if each character matches 0x4F.
If it does, I then check to see if the next char matches 0x67 and so
on. This gives me four nestled if blocks. I also have to deal with
buffering the data.
Can anyone offer a better solution written in native C/C++
Thanks
a good algorithm for it. Currently I just have a horrible looking
nestled 'if' blocks, so hopefully someone can help me out with a more
elegant solution.
I have a large binary file. Essentially the binary file contains 1 or
more paragraphs. Each paragraph starts with a four byte sequence:
0x4F 0x67 0x67 0x53
In my C++ application I open a fstream to the file in binary mode. I
want to iterate through the file, and pass each paragraph into a new
class which will know what to do with it.
I have been using a read() to copy a chunk of data into a buffer, then
iterate through the buffer checking if each character matches 0x4F.
If it does, I then check to see if the next char matches 0x67 and so
on. This gives me four nestled if blocks. I also have to deal with
buffering the data.
Can anyone offer a better solution written in native C/C++
Thanks