I know that strtod()
and atof()
functions are used for conversion from string to double.
But I can't figure out the difference between these two functions.
Is there any difference between these two functions, if yes then please let me know...
Thanks in Advance.
From the man page on
double atof(const char *nptr)
:Why can't it detect errors? Well, because that second argument of
double strtod(const char *nptr, char **endptr)
is used to point to the last character that couldn't be converted, so you can handle the situation accordingly. If the string has been successfully converted,endptr
will point to\0
. Withatof
, that's set toNULL
, so there's no error handling.An example of error handling with
strtod
: