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:
#include <stdio.h>
#include <string.h>
main() {
char numstring[] = "12.34";
double d;
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.
Any ideas?