Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ strtol(3) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

strtod, atof

scanf, fscanf, sscanf, NLscanf, NLfscanf, NLsscanf, wsscanf



STRTOL(3,L)                 AIX Technical Reference                 STRTOL(3,L)



-------------------------------------------------------------------------------
strtol, atol, atoi



PURPOSE

Converts a string to an integer.

LIBRARY

Standard C Library (libc.a)

SYNTAX



      long strtol (str, ptr, base)        long atol (str)
      char *str, **ptr;                   char *str;
      int base;
                                          int atoi (str)
                                          char *str;



DESCRIPTION

The strtol subroutine returns a long integer whose value is represented by the
character string str.  strtol scans the string up to the first character that
is inconsistent with the base.  Leading whitespace characters are ignored.

Warning:  Overflow conditions are ignored.

If the value of ptr is not (char **) NULL, a pointer to the character that
terminated the scan is stored in *ptr.  If an integer cannot be formed, *ptr is
set to str, and 0 is returned.

If the base parameter is positive and not greater than 36, it is used as the
base for conversion.  After an optional leading sign, leading zeros are
ignored.  "0x" or "0X" is ignored if base is 16.

If the base parameter is 0, the string determines the base.  Thus, after an
optional leading sign, a leading 0 indicates octal conversion, and a leading
"0x" or "0X" indicates hexadecimal conversion.  The default is to use decimal
conversion.

Note:  Truncation from long to int can take place upon assignment, or by an
       explicit cast.

The atol (str) subroutine call is equivalent to strtol (str, (char **) NULL,
10).




Processed November 7, 1990        STRTOL(3,L)                                 1





STRTOL(3,L)                 AIX Technical Reference                 STRTOL(3,L)



The atoi (str) subroutine call is equivalent to (int) strtol (str, (char **)
NULL, 10).

The atoi and atol subroutines do not actually call strtol.

The strtol, atol, and atoi subroutines perform conversions to integers.  See
"strtod, atof" for information on conversions to floating-point numbers.

ERROR CONDITIONS

The strol, atol, and atoi subroutines fail if one of the following is true:

EINVAL    The value of base is not supported.

ERANGE    The value to be returned would cause an overflow.

RELATED INFORMATION

In this book:  "strtod, atof" and "scanf, fscanf, sscanf, NLscanf, NLfscanf,
NLsscanf, wsscanf."



































Processed November 7, 1990        STRTOL(3,L)                                 2



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026