Convert string to long double precision floating-point value.
Include
<stdlib.h>
Prototype
long double strtold(const char * restrict nptr, char ** restrict
endptr);
Argument
nptr | |
endptr |
Return Value
The converted value, or 0 if the conversion could not be performed.
Remarks
The strtold
function attempts to convert the first part
of the string pointed to by nptr
to a long double
floating-point value.
The initial section consists of any white-space characters.
e
or E
followed by an option sign and
decimal digits0x
or
0X
, then a nonempty sequence of hexadecimal digits
optionally containing a decimal-point character, then an optional binary
exponent part, being p
or P
, and an
optional sign, and decimal digits.INF
or INFINITY
, ignoring caseNAN
,
ignoring case, optionally followed by any sequence contain digits or
non-digits:endptr
, provided that endptr
is not a null
pointer.The final section consists of characters in the string that were unrecognized in the
subject section and which will include the terminating null character of the string.
This section of the string will be accessible via the address stored to
endptr
, provided endptr
is not a null
pointer.
The value of the macro ERANGE
is stored in errno
if
the correct value of the conversion is outside the range of representable values. If
the result underflows, ***whether errno
acquires the value ERANGE
is implementation-defined***
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
char * string = " +0.137e2 mSec";
char * final;
long double result;
result = strtold(string, &final);
printf("The floating-point conversion of the string \"%s\" is %Lg; final string part is \"%s\"\n", string, result, final);
}
Example Output
The floating-point conversion of the string " +0.137e2 mSec" is 13.7; final string part is " mSec"