Borland C++ reference

strtod, _strtold

raw OCR

Convert a string to a double or long double value.

Defined in header <stdlib.h>

Syntax

#include <stdlib.h>
double  strtod(const char *s, char **end-ptr);
long double  _strtold(const char *s, char **endptr);

Portability

DOSUNIXWindowsANSI CC++ only
strtod ■■■■
strtold ■■

Remarks

strtod converts a character string, s, to a double value, s is a sequence of characters that can be interpreted as a double value; the characters must match this generic format:

[ws] [sn] [ddd][ddd] [fmt[sn]ddd]

where

[zvs] = optional whitespace

[sn]= optional sign (+ or -)

[ddd] = optional digits [fmt] - optional e or £

[.]- optional decimal point

strtod also recognizes +INF and -INF for plus and minus infinity, and +NAN and -NAN for Not-a-Number.

For example, here are some character strings that strtod can convert to double:

+ 1231.1981 e-1 502.85E2 + 2010.952

strtod stops reading the string at the first character that cannot be interpreted as an appropriate part of a double value.

If endptr is not null, strtod sets *endptr to point to the character that stopped the scan (*endptr = &cstopper). endptr is useful for error detection.

_strtold is the long double version; it converts a string to a long double value.

Return value

These functions return the value of s as a double (strtod) or a long double (_strtold). In case of overflow, they return plus or minus HUGEVAL

(strtod) or _LHUGE_VAL(_strtold).

See also

Example

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

int main(void)
{
   char input[80], *endptr;
   double value;
  , printf("Enter a floating point number:");
   gets (input);
   value = strtod(input, &endptr) ;
   printf("The string is %s the number  is %lf\n", input, value)
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.

Extraction notes

  • heading `strtod, strtold` read as `strtod, _strtold`