0

Hi i have an android project which uses ndk

there is a c function atof() which is defined

static __inline__ double atof(const char *nptr)
{
    return (strtod(nptr, NULL));
}

But somehow it always results in 0.0

error_printf("found %s parsed %d \n",nextArg, atof(nextArg));
found 44 parsed 0

any ideas why?

the parameter nextArg seems not to be the Problem

error_printf("found %s parsed %d \n","123", atof("123"));
found 123 parsed 0 
wutzebaer
  • 14,365
  • 19
  • 99
  • 170

1 Answers1

2

Change your print message from %d, which expects a 32-bit integer, to %f, which expects a 64-bit floating-point value.

Your print statement is showing the low 32 bits of its argument, which happen to be all zeroes because of your chosen test input. If you printed atof(123.3) you'd see a nonzero value from %d.

And, of course, make sure you have #include <stdlib.h> to ensure you have the prototypes for atof() and strtod().

fadden
  • 51,356
  • 5
  • 116
  • 166