strtod
double  strtod ( const char * string, char** endptr );
stdlib.h
  cplusplus.com  

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.

Parameters.

string
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:
[whitespaces][+|-][nnnnn][.nnnnn][e|E[+|-]nnnn]
(where whitespaces are any tab or space character and nnnnn may be any number of digits)
endptr
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.

Portability.
  Defined in ANSI-C.

Example.

/* 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