[Vala] How to write float and double values into a binary file?
- From: Sepehr Aryani <sepehr aryani gmail com>
- To: vala-list gnome org
- Subject: [Vala] How to write float and double values into a binary file?
- Date: Wed, 15 Dec 2010 03:27:07 +0800
I'm wondering how to write a float or double value into a binary file.
Well, 'FileStream.write' api looks like below:
public size_t <http://valadoc.org/glib-2.0/size_t.html> *write* (
uint8 <http://valadoc.org/glib-2.0/uint8.html>[] buf,
size_t<http://valadoc.org/glib-2.0/size_t.html> size
= 1)
I have to cast my floating point number into integer which in my case it is
useless...
In fact it seems impossible to me, because i failed to do that, Since write
function
needs an array of one-byte-values and I have a float value!!!
If I use 'FileStream.printf' function, it writes data into file in ascii
format.
this is my code sample:
public void main(){
float flt = 9.12f;
var output = FileStream.open("./data.bin","w+b");
output.printf("%f", flt);
float? in_flt = null;
var input = FileStream.open("./data.bin", "r+b");
input.scanf("%f", in_flt); // !!!error
}
I need a way write in floating point format and read in the same format,
without casting...
What should i do?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]