Alex Rivera | Logout

C parsing double from argument strings

Asked 2010-02-08T08:18:28.140
11

I'm trying to parse an argument value in C and convert the number to a double value. I have:

char *stringEnd; double num = strtod("123.0", &stringEnd);

I used "123.0" just to test the function, but it always returns a value of 0.0. Does anybody know what I'm doing wrong?

Edit
Report

1 Answer

2

You can use sscanf.

double num;
sscanf("123.0", "%lf", &num);
answered 2010-02-08T08:20:54.813

Your Answer