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?
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 (
-Wallon GCC).If you get a warning about
strtodbeing 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!