strtold - C stdlib.h

C examples for stdlib.h:strtold

Type

function

From


<cstdlib>
<stdlib.h>

Description

Convert string to long double and returns its value as a long double.

Prototype

long double strtold (const char* str, char** endptr);

Parameters

Parameter Description
str C string representation of a floating-point number.
endptr type char* set by the function to the next character in str after the numerical value.

Return Value

On success, the function returns the converted floating point number as a value of type long double.

For non valid conversion, the function returns zero (0.0L).

For out of the range values, a positive or negative HUGE_VALL is returned, and errno is set to ERANGE.

Demo Code


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

int main ()//  www  .  j  a v  a  2 s .  c  o  m
{
  char str[] = "1234.305 12345.24 test";
  
  char * pEnd;
  
  long double f1, f2;
  
  f1 = strtold (str, &pEnd);
  
  f2 = strtold (pEnd, NULL);
  
  printf ("%Lf\n", f1);
  
  printf ("%Lf\n", f2);
  
  return 0;
}

Related Tutorials