2

I suppose I am just stupid (I tried all). Help me out of here:

#include <stdio.h>
#include <string.h>
int main()
{
    const char * y = "747.0";
    double x;
    x = atof(y);
    printf("%.5f\n",x);
    printf("%e\n",x);
    return 0;
}

result:

0.00000
0.000000e+00
user2864740
  • 60,010
  • 15
  • 145
  • 220
varantir
  • 6,624
  • 6
  • 36
  • 57

2 Answers2

6

You need to include stdlib.h to offer atof() a prototype, without proper prototype, compiler will suppose its return value be an int.

Lee Duhem
  • 14,695
  • 3
  • 29
  • 47
0

Try including stdlib.h because I think that is the package you need for atoi in C.