Using write introduces an endianness dependency. Thus, you will have to change the byte order when you read the file again.
Otherwise, your code will be fine. Have you tried writing another reading program in the same way and comparing the results?
The whole point of using write is to avoid converting to text.
int main(){ float f; read(0,&f,sizeof(float) ); printf( "%f", (double) f ); return 0; }
Run from shell as
write_test | read_test
source share