Quote:Original post by Boogy
Found that its better to use fwrite :P
Take care when using fwrite to write POD structs. The compiler can insert padding between elements and that padding (bytes of undetermined value) will also be written to your file.
Different compilers are at liberty to insert different amounts of padding, so if you compile your code on a different system (or with a different compiler on the same system) the generated program might not write compatible data. Of course the same applies to fread-ing into structs; if the compiled layout differs between two programs, your data format is not portable (at best) or broken (at worst).
Most compilers provide a mechanism such as a pragma to ensure that padding isn't inserted between elements (at least on x86 where alignment isn't strict).