C parsing double from argument strings

You if have to use strtod in order to use:

double num = strtod("123.0", NULL);

you can also use sscanf

double num;    
sscanf("123.0", "%lf", &num);

You need to #include stdlib.h.


You can use sscanf.

double num;
sscanf("123.0", "%lf", &num);

Are you including the relevant header? ie: #include <stdlib.h>

First though (and you should be doing this all the time anyway), try compiling with all warnings on (-Wall on GCC).

If you get a warning about strtod being undefined, that shows where the problem is coming from.

This is a nasty one, because C will implicitly declare any function it doesn't have a prototype for as returning int!