I have a binary file which contains data in 128-byte blocks that are spread across the file. Each block starts with a char array of length 8.

How do I reorganize the data in this binary file such that all 128-byte blocks are ordered sequentially and that there is no unused space between these blocks?

Unused/unallocated space is just represented by 0 in this file and strings are null terminated.

I'm quite lost.

1 Answers

0
quantummind On

Your question is not a complete specification, e.g.:

 - what is unused space?
 - do the char arrays contain string terminator or not?
 - is the file small enough to read into memory, or is it large?

So I cannot write it to you. However you can program it easily if you follow these instructions:

1. Build a list of pointers to the used 128 bytes blocks.
2. Sort that list.
3. You can now overwrite the file looping through the ordered list of pointers.