c - atof always returns 0.0 under Linux platform
PHP中文网
PHP中文网 2017-07-05 10:45:54
0
1
1088

code show as below

#include<stdio.h>

int main(){


   char* s = "123.3";
   double d = atof(s);
   printf("%lf\n", d);

   return 0;
}

The result is always 0.000000, not 123.3, why?

PHP中文网
PHP中文网

认证0级讲师

reply all(1)
迷茫

Because you didn’t include stdlib.h ( ゜ロ゜)”
This is a hidden pit. Because you did not include the header file, there is no function declaration. Without a function declaration, the default return value of the library function is int type.
If you add -Wall when compiling, it will clearly tell you that it is not declared.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template