double  strtod ( const char * string, char** endptr );

Convert string to double-precision floating-point value.
  Parses string interpreting its content as a floating-point value until a character that can not be interpreted is found, and returns a double precision value.


String representing a floating point number. The number is considered until a non-numeric character is found (digits, signs, E and e are considered valid numeric characters for this parameter as specified in format). The format used is:
(where whitespaces are any tab or space character and nnnnn may be any number of digits)
Address of a pointer. This is filled by the function with the address where scan has ended. Serves to determine where there is the first non-numerical character in the string.

Return Value.
  The converted double value from the input string.
  If conversion would cause overflow the result is +/- HUGE_VAL .
  If an error occurs 0 is returned.

  Defined in ANSI-C.


/* strtod example */
#include <stdio.h>
#include <stdlib.h>

main ()
  char szInput [256];
  char * pEnd;
  double dbl;
  printf ("Enter a floating-point value: ");
  gets (szInput);
  dbl = strtod (szInput,&pEnd);
  printf ("Value entered: %lf. Its square: %lf\n",dbl,dbl*dbl);
  return 0;

See also.
  atof, strtol, strtoul

© The C++ Resources Network, 2000