atof(S) 6 January 1993 atof(S) Name atof, atoi, atol - converts ASCII to numbers Syntax cc . . . -lc #include <stdlib.h> double atof (nptr) char *nptr; int atoi (nptr) char *nptr; long atol (nptr) char *nptr; Description 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 charac- ters 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 charac- ters 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: [ +|- ] digits where 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. Note If a value cannot be represented, the behavior is undefined. See also scanf(S) Standards conformance atof, atoi and atol are conformant with: AT&T SVID Issue 2; X/Open Portability Guide, Issue 3, 1989; Intel386 Binary Compatibility Specification, Edition 2 (iBCSe2); and ANSI X3.159-1989 Programming Language -- C.