Can not use the function „strtod“

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Can not use the function „strtod“

1,288件の閲覧回数
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 件の賞賛
返信
2 返答(返信)

928件の閲覧回数
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

928件の閲覧回数
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 件の賞賛
返信