|
|
#include <stdlib.h>double atof (nptr) char *nptr;
int atoi (nptr) char *nptr;
long atol (nptr) char *nptr;
These functions convert a string pointed to by nptr to double, integer, and long integer numbers respectively. The first unrecognized character ends the string.
The atof function converts a string to a double. The string pointed to by nptr is converted up to the first character deemed to be inconsistent with the format of a floating-point number. Leading white-space characters are ignored. This call is analogous to:
strtod(str, (char **) NULL)atof recognizes a string of the form:
[ +|- ] digits[. digits ][ e|E [ +|- ] digits ]where the digits are contiguous decimal digits. Any number of tabs and spaces may precede the string. The ``+'' and ``-'' signs are optional. Either e or E may be used to mark the beginning of the exponent. If the atof function fails due to overflow or underflow, errno is set to ERANGE. The maximum size of an exponent is set by DMAXEXP, which is defined in the /usr/include/values.h header file.
The atoi function converts the string pointed to by nptr to an integer. Processing stops when up to the first character inconsistent with the format of a decimal integer is encountered. Leading white-space characters is ignored. This call is analogous to the following except that an integer is returned.
strtol(str, (char **) NULL, 10)atoi and atol recognize strings of the form:
[ +|- ] digitswhere the digits are contiguous decimal digits. Any number of tabs and spaces may precede the string. The ``+'' and ``-'' signs are optional. If the atoi routine fails due to overflow or underflow, errno is set to ERANGE.
The atol function converts the string pointed to by nptr up to the first character inconsistent with the format of a decimal integer, ignoring leading white-space characters, to a long. This call is analogous to:
strtol(str, (char **) NULL, 10)If the atoi function fails due to overflow or underflow, errno is set to ERANGE.
X/Open Portability Guide, Issue 3, 1989
;
Intel386 Binary Compatibility Specification, Edition 2 (iBCSe2)
;
and
ANSI X3.159-1989 Programming Language -- C
.