Can not use the function „strtod“

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can not use the function „strtod“

774 Views
soli
Contributor I

Hello,

 

I have to translate numbers from string to double. Therefor I would like to use the function “strtod(char *x, char **y)”

 

I test this with following code:

 

double   result           = 0;

char     *sub_str_end     = NULL;

char test[] = "1.234";

 

//! Test 1

result = strtod(test, NULL);

 

//! Test 1

sub_str_end = test+4;

result = strtod(test, &sub_str_end);

 

if (errno != 0)

    printf("ERRNO\n");

 

 

But if I use this code, I get the number “-927712936.000000” for result.

Does anyone has an idea why this not work? (Are there missing compiler settings?)

 

Thanks.

 

0 Kudos
2 Replies

414 Views
c0170
Senior Contributor III

Hello soli,

 

your program uses compilers strtod, you haven't specified which one, if it was for CW,IAR or KEIL.

Anyway, MQX provides its function called _io_strtod which is located in a file io_fp.c in the directory source/fio.

 

Try _io_strtod and share with us if it works for your case.

 

Regards,

MartinK

414 Views
soli
Contributor I

Thank you Kojto,

 

_io_strtod is working well. (I use CW)

 

But I do not understand why the normal strtod does not work? Because it is a normal standard function in C.

 

0 Kudos