I used the following piece of code to read data from files as part of a larger program.
double data_read(FILE *stream,int code) { char data[8];
Using a union is not the correct thing to do here. Reading from an unwritten member of the union is undefined - i.e. the compiler is free to perform optimisations that will break your code (like optimising away the write).