Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ strtol(S) — System V/386 Software Development System 3.2.2b

Media Vault

Software Library

Restoration Projects

Artifacts Sought



     STRTOL(S)                 UNIX System V                 STRTOL(S)



     Name
          strtol, atol, atoi - convert string to integer

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

          long atol (str)
          char *str;

          int atoi (str)
          char *str;

     Description
          The strtol function returns as a long integer the value
          represented by the character string pointed to by str.  The
          string is scanned up to the first character inconsistent
          with the base.  Leading ``white-space'' characters (as
          defined by isspace in ctype(S)) are ignored.

          If the value of ptr is not (char **)NULL, a pointer to the
          character terminating the scan is returned in the location
          pointed to by ptr.  If no integer can be formed, that
          location is set to str, and zero is returned.

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

          If base is zero, the string itself determines the base.
          After an optional leading sign a leading zero indicates
          octal conversion, and a leading ``0x'' or ``0X'' hexadecimal
          conversion.  Otherwise, decimal conversion is used.

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

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

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

     See Also
          ctype(S), scanf(S), strtod(S)

     Diagnostics
          If the argument ptr is a null-pointer, the function strtol
          will return the value of the string str as a long integer.

          If the argument ptr is not NULL, the function strtol will
          return the value of the string str as a long integer, and a
          pointer to the character terminating the scan will be
          returned in the location pointed to by ptr.

          If no integer can be formed, that location is set to the
          argument str and the function strtol returns 0.

     Note
          Overflow conditions are ignored.

     Standards Conformance
          atoi and atol are conformant with:
          AT&T SVID Issue 2, Select Code 307-127;
          The X/Open Portability Guide II of January 1987;
          ANSI X3.159-198X C Language Draft Standard, May 13,
          1988;
          IEEE POSIX Std 1003.1-1988 with C Standard Language-
          Dependent System Support;
          and NIST FIPS 151-1.

          strtol is conformant with:
          AT&T SVID Issue 2, Select Code 307-127;
          The X/Open Portability Guide II of January 1987;
          and ANSI X3.159-198X C Language Draft Standard, May 13,
          1988.

                                             (printed 6/20/89)



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