search

Home  >  Q&A  >  body text

c - atof always returns 0.0 under Linux platform

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中文网2788 days ago1116

reply all(1)I'll reply

  • 迷茫

    迷茫2017-07-05 10:47:54

    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.

    reply
    0
  • Cancelreply