J
Jonathan Lamothe
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I've written a program that requires the user to input a decimal number
which is then stored as a float.
First it's read into a variable buf which is an array of 16 characters
like this:
fgets(buf, 16, stdin);
I then tried to convert it into a float and store it in another variable.
val = strtof(buf, (char **)NULL);
For some reason, all numbers other than 0 are not being converted
properly. Am I doing something wrong?
I've changed the line of code to read like this:
val = (float)strtod(buf, (char **)NULL);
The second line of code is working fine, but it still bothers me that
the first one isn't.
If anyone wants to see the source a tarball is available at
ftp://linserv.homeip.net/src/tempconv
- --
Regards,
Jonathan Lamothe
QOTD:
"Backups are for wimps. Real men upload their data to an FTP site and
have everyone else mirror it."
-- Linus Torvalds
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCRxRBNrv4JaRC3JsRAsqwAJ483+dEEJYbR7nerGoGDwyBO4W2pACeJbrQ
kM69g/hPe60nF34XbYgnOoM=
=g0AN
-----END PGP SIGNATURE-----
Hash: SHA1
I've written a program that requires the user to input a decimal number
which is then stored as a float.
First it's read into a variable buf which is an array of 16 characters
like this:
fgets(buf, 16, stdin);
I then tried to convert it into a float and store it in another variable.
val = strtof(buf, (char **)NULL);
For some reason, all numbers other than 0 are not being converted
properly. Am I doing something wrong?
I've changed the line of code to read like this:
val = (float)strtod(buf, (char **)NULL);
The second line of code is working fine, but it still bothers me that
the first one isn't.
If anyone wants to see the source a tarball is available at
ftp://linserv.homeip.net/src/tempconv
- --
Regards,
Jonathan Lamothe
QOTD:
"Backups are for wimps. Real men upload their data to an FTP site and
have everyone else mirror it."
-- Linus Torvalds
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCRxRBNrv4JaRC3JsRAsqwAJ483+dEEJYbR7nerGoGDwyBO4W2pACeJbrQ
kM69g/hPe60nF34XbYgnOoM=
=g0AN
-----END PGP SIGNATURE-----