0

I´m learning to use these functions that change a string to an int or double, but atof doesn´t work for me.

char cadena[20]="3.1416";
double x=atof(cadena);
printf("%g",x);

I have this simple code, but the output of x is 7.73471e+006. Why? Atoi works fine. I´m using mingw compiler, if that could be the error.

IssacCloudVII
  • 41
  • 1
  • 5
  • 2
    What is your locale? What about `char cadena[20]="3,1416";`? Try adding `setlocale(LC_ALL, "");`. – KamilCuk Apr 20 '20 at 07:52
  • 2
    You probably didn't include ``, where `aotf` is declared, so the compiler makes the wrong assumprions about the involved types. Turn on warnings to get notified about missing prototypes. – M Oehm Apr 20 '20 at 07:55

0 Answers0