How should a program read and write float numbers from and into binary files in C or Vala language?
The common APIs to do writing and reading are generally designed to write in byte format. I mean you have to write arrays of one-byte data into file and read in the same format.
I'm looking for a way to write and read in float format. without typecasting and without having to change the number into string. Is it possible?
fwrite() and fread() or write() and read() will work just fine.
float da, db ;
...
fwrite( &da, 1, sizeof(da), fpout ) ;
...
fread( &db, 1, sizeof(db), fpin ) ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With