I don\'t know which direction to go,perhaps something like reflection will help?
What do you want to do with your file once you've got it? If it's going to be read back in at a later time just use fread
and fwrite
, like
struct foo * bar;
fwrite(bar,sizeof(*bar),1,stdout);
...
fread(bar,sizeof(*bar),1,stdin);
This will give binary output that's dependant on your compiler/platform, as long as those are unchanged you should be fine. From there you can also feed the file into a hex reader etc., though you'll need to know the layout of the struct to do anything useful with it.