atof(3C)
_________________________________________________________________
atof function
Convert an ASCII string into a floating-point number.
_________________________________________________________________
Calling Sequence
double result, atof();
char *string;
result = atof(string);
where string begins with a valid arithmetic expression.
Description
Use the atof function to convert an ASCII string into a double-
precision floating-point number. The atof function skips leading
whitespace characters (e.g., blank, tab) and conversion stops
when the function encounters an invalid character. However, atof
recognizes the characters e and E as indicators of exponents and
handles them correctly.
The include file dg_stdio.h defines this function.
Returns
The atof function returns the floating-point number that it
converted the string to. If an error occurs, atof returns 0 and
sets the variable errno to ERANGE.
Related Functions
See also the ftoa, atoi, atol, atou, sscanf, and strtod
functions.
Example
/* Program test for the atof() function */
#include <stdio.h>
double result, atof();
main() {
printf("%f\n", result = atof(" -12.03e12"));
printf("%f\n", result = atof("0.07E-1"));
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
atof(3C)
printf("%f\n", result = atof(" 19.81"));
printf("%f\n", result = atof("19b81"));
}
The output from the program test is
-12030000000000.000000
0.007000
19.810000
19.000000
The atof function skipped leading whitespace characters, treated
the hyphen as a minus sign, and treated the characters 'e' and
'E' as exponents. However, the function stopped processing the
last string after encountering the b, which is an invalid
character.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)