Read file structure

So the problem is that I need to cast the file string to a variadic struct (if this exist). Something like this:

1
2
3
4
5
6
7
8
char* FileString;

struct FileFormat {
unsigned long AmountData;
char Data[ AmountData ];
} ;

FileFormat FileStruct = FileString;


Is this is possible? I tried making pointer and allocating memory for it but I don't think this is effective.
Nothing wrong with that approach.

You could make your life a little easier by using a container that takes care of its own size if you don't want to have to read the size and allocate the correct memory yourself.

Yeah but in this case I need to keep an 4 bytes dword (for memory pointer) more in every file structure and maybe even more 4 (for saving the allocated memory size by malloc()). Let's thought I have 200 objects with a variadic struct and the result is : 1600 ( 200*8 ) bytes more than that in the file struct.
Is there some problem with using 1600 bytes to store your extra information?
Not by I reverse engineering a program which has a char string with the file inside it and and the data there are used by the program directly. When I use an allocated memory the file string will be split into small parts. I want to know a approach that have the same behavior like this program.

EDIT: Anyway I found a way placing the structure to point in the char string.
Last edited on
Topic archived. No new replies allowed.