I am trying to convert a character array into double in c using atof and receiving ambiguous output.
printf("%lf\n",atof("5"));
prints
262144.000000
I am stunned. Can somebody explain me where am I going wrong?
I am trying to convert a character array into double in c using atof and receiving ambiguous output.
printf("%lf\n",atof("5"));
prints
262144.000000
I am stunned. Can somebody explain me where am I going wrong?
Make sure you have included the headers for both atof and printf. Without prototypes the compiler will assume they return
int
values. When that happens the results are undefined, since that doesn't match atof's actual return type ofdouble
.No prototypes
Prototypes
Lesson: Pay attention to your compiler's warnings.
I fixed a similar problem by having a decimal point and at least 2 zeros after the decimal point with