### strtold -- Convert String to Long Double

Format

>     #include <stdlib.h>
>     long double strtold(const char *nptr, char **endptr);

Language Level: Extension
strtold converts a character string to a long double value. The parameter nptr points to a sequence of characters that can be interpreted as a numerical value of the type long double. When it reads a character that it does not recognize as part of a number, strtold stops reading the string at that character, and sets endptr to point to the remainder of nptr. The character at which strtod stops reading the string may be the null character at the end of that string.

The string pointed to by nptr must have the following format:

The digits are one or more decimal digits. If no digits appear before the decimal point, at least one digit must follow the decimal point. An exponent expressed as a decimal integer can follow the digits. The exponent can be signed.

The value of nptr can also be one of the strings infinity, inf, or nan. These strings are case insensitive, and can be preceded by a unary minus (-). They are converted to infinity and NaN values.

If the string pointed to by nptr does not have the expected form, no conversion is performed and endptr points to the value of nptr.

Return Value
If successful, strtold returns the value of the long double number. If it fails, strtold returns 0. For an underflow or overflow, it returns the following:

Condition | Return Value
Underflow | 0 with errno set to ERANGE
Positive overflow | +_LHUGE_VAL
Negative overflow | -_LHUGE_VAL.

Example
This example uses strtold to convert two strings, " -001234.5678e10end of string" and "NaNthis cannot be converted" to their corresponding long double values. It also prints out the part of the string that cannot be converted.

    #include <stdlib.h>
    #include <stdio.h>

    int main(void)
    {
       char *nptr;
       char *endptr;

       nptr = "  -001234.5678e10end of string";
       printf("strtold = %.10Le\n", strtold(nptr, &endptr));
       printf("end pointer at = %s\n\n", endptr);
       nptr = "NaNthis cannot be converted";
       printf("strtold = %.10Le\n", strtold(nptr, &endptr));
       printf("end pointer at = %s\n\n", endptr);
       return 0;

       /***************************************************
          The output should be:

          strtold = -1.2345678000e+13
          end pointer at = end of string

          strtold = nan
          end pointer at = this cannot be converted
       ***************************************************/
    }

atof -- Convert Character String to Float
atoi -- Convert Character String to Integer
atol -- Convert Character String to Long Double
_atold -- Convert Character String to Long Double
strtod -- Convert Character String to Double
strtol -- Convert Character String to Long Integer
strtoul -- Convert String Segment to Unsigned Integer
wcstod -- Convert Wide-Character String to Double
wcstol -- Convert Wide-Character to Long Integer
wcstoul -- Convert Wide-Character String to Unsigned Long
<stdlib.h>