strtod

Converts a given string to a double-precision number.

Format

#include  <stdlib.h>

double strtod  (const char *nptr, char **endptr);
Function Variants This function also has variants named _strtod32 and _strtod64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.8 for more information on using pointer-size-specific functions.

Arguments

nptr
A pointer to the character string to be converted to a double- precision number.
endptr
The address of an object where the function can store the address of the first unrecognized character that terminates the scan. If endptr is a NULL pointer, the address of the first unrecognized character is not retained.

Description

This function recognizes an optional sequence of white- space characters (as defined by isspace), then an optional plus or minus sign, then a sequence of digits optionally containing a radix character, then an optional letter (e or E) followed by an optionally signed integer. The first unrecognized character ends the conversion.

The string is interpreted by the same rules used to interpret floating constants.

The radix character is defined the program's current locale (category LC_NUMERIC).

This function returns the converted value. For strtod, overflows are accounted for in the following manner:

If the string starts with an unrecognized character, then the conversion is not performed, *endptr is set to nptr, a 0 value is returned, and errno is set to EINVAL.)

Return Values
The converted string. 
Indicates the conversion could not be performed. errno is set to one of the following:

  • EINVAL - No conversion could be performed.

  • ERANGE - The value would cause an underflow.

  • ENOMEM - Not enough memory available for internal conversion buffer.
 
(+/-)HUGE_VAL  Indicates overflow. errno is set to ERANGE. 


Previous Page | Next Page | Table of Contents | Index