The strtod(3) Function

The strtod(3) function is used to perform string-to-floating point conversions. This function is quite similar in operation to the integer conversion functions just covered, but it has a few new wrinkles. The synopsis for strtod(3) is as follows:

#include <stdlib.h>
#include <math.h>

double strtod(const char *nptr, char **endptr);

Note that there is no base argument. No radix conversions are available for floating-point conversions other than base 10.

The input string nptr and the second argument endptr are used in precisely the same way they are used in the strtol(3) function.

Using the strtod(3) Function

The following shows how the strtod(3) function can be used to convert a floating-point value in a string buffer to ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.