Can not use the function „strtod“

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Can not use the function „strtod“

792 次查看
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 回复数

432 次查看
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

432 次查看
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 项奖励