Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ strtol(S) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

atof(S)

ctype(S)

scanf(S)

strtod(S)


 strtol(S)                      6 January 1993                      strtol(S)


 Name

    strtol - convert string to integer

 Syntax


    cc  . . .  -lc


    #include  <stdlib.h>
    #include  <limits.h>        /* ANSI-only */

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


 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 ter-
    minating 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 take place upon assignment or by an ex-
    plicit cast.

    Upon successful completion, strtol returns the converted value, if any.
    If the correct value causes overflow, and you are compiling with the cc
    -ansi flag, errno is set to ERANGE and LONGMIN is returned if the value
    is negative, and LONGMAX is returned if the value is positive.
    (LONGMIN and LONGMAX are defined in limits.h.) For all other confor-
    mance standards, the value returned is either a positive or negative long
    integer and ERANGE is returned in errno.  For all other errors, zero is
    returned and errno indicates the error.  EINVAL is returned when the
    value of base is not supported.


 See also

    atof(S), ctype(S), scanf(S), strtod(S)

 Standards conformance

    strtol is conformant with:
    AT&T SVID Issue 2;
    X/Open Portability Guide, Issue 3, 1989;
    and ANSI X3.159-1989 Programming Language -- C.


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