atof
double  atof ( const char * string );
math.h
stdlib.h
  cplusplus.com  

Convert string to double.
  Parses string interpreting its content as a floating point number and returns a value of type double.

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)

Return Value.
  The converted floating point value of the input string.
  On overflow the result is undefined.
  If an error occurs 0.0 is returned.

Portability.
  Defined in ANSI-C.

Example.

/* atof example: sines calculator */
#include <stdio.h>
#include <math.h>

main ()
{
  double n,m;
  double pi=3.1415926535;
  char szInput [256];
  printf ( "Enter degrees: " );
  gets ( szInput );
  n = atof ( szInput );
  m = sin (n*pi/180);
  printf ( "sine of %f degrees is %f\n" , n, m );
  return 0;
}
Output:
Enter degrees: 45
sine of 45.000000 degrees is 0.707101

See also.
  cstdlib/strtod


© The C++ Resources Network, 2000