atof() and sscanf() do not work for me
Posted on 2002-07-09
I'm trying to convert a string into a double. I've tried both the atof() and sscanf() functions with no success. What am I doing wrong?
I am running on a Solaris 2.8 UNIX box.
Here is the code:
char numstring = "12.34";
d = atof(numstring);
printf("String = %s\n",numstring);
printf("Double = %f\n",d);
Here are the results:
String = 12.34
Double = -4264242.000000
Playing around with the format string in the second printf statement seems to change the answer, but not to 12.34.
Using sscanf() instead of atof() yields different incorrect results.