J
Jim
I recently had to extract some data from some data files handed to us. Part
of the data to extract was a floating point value representing a weight. As
we didn't have the file formats I had to guess where the float would be. As
I knew what the weight was on one record I decided to knock up a quick
programme to output the value 9.5 as a float so I could see where it was in
the other file. However, I'm doing something wrong.
The code I knocked up was this:
#include <stdio.h>
void main()
{
double f = 9.5;
FILE *outfile;
outfile=fopen("jim.test","wb");
fprintf(outfile, "%f", f );
fclose(outfile);
}
However, this produced the following file (hexdumped):
39 2E 35 30 30 30 30 30
which is literally '9.500000', when the actual byte stream should have been
00 00 18 41 (Intel)
So: what _should_ I have written in order to get the four-byte float in the
file instead of what appears to be the plain text version?
It's a moot point as I got the data anyway, but I'm curious.
Many thanks.
Jim
of the data to extract was a floating point value representing a weight. As
we didn't have the file formats I had to guess where the float would be. As
I knew what the weight was on one record I decided to knock up a quick
programme to output the value 9.5 as a float so I could see where it was in
the other file. However, I'm doing something wrong.
The code I knocked up was this:
#include <stdio.h>
void main()
{
double f = 9.5;
FILE *outfile;
outfile=fopen("jim.test","wb");
fprintf(outfile, "%f", f );
fclose(outfile);
}
However, this produced the following file (hexdumped):
39 2E 35 30 30 30 30 30
which is literally '9.500000', when the actual byte stream should have been
00 00 18 41 (Intel)
So: what _should_ I have written in order to get the four-byte float in the
file instead of what appears to be the plain text version?
It's a moot point as I got the data anyway, but I'm curious.
Many thanks.
Jim