Generally, the code
will only work if the read and write is on the same platform. Floating point numbers are generally IEEE 754, but it's not guaranteed.Code:double x; FILE *fp; fwrite(x, 1, sizeof(x), fp); ... fread(&x, 1, sizeof(x), fp);
I've written routines which read and write in IEEE 754 format, portably. If the native format is not IEEE 754 then you necessarily lose a few bits of precision, but you get the closest representation possible on your native machine.
GitHub - MalcolmMcLean/ieee754: Ieee754 floating point routines, load and save ieee 754 even on non-ieee 754 hardware.