Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ atol(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                                 atol(3C)



        _________________________________________________________________
        atol                                                     function
        Convert an ASCII string to type long.
        _________________________________________________________________


        Calling Sequence

        long result, atol();
        char *string;
        result = atol(string);



          where   result is of type long.

                  string is a byte pointer to a character array that
                  contains optional spaces, an optional plus or minus
                  sign, and a string of digits.



        Description

        Use the atol function to convert an ASCII string to type long.
        The function ignores leading whitespace (blanks or tabs) and
        stops scanning at the first nondigit it encounters.  The function
        follows C conventions for radix specification.

        The include file dg_stdio.h defines this function.


        Returns

        The atol function returns the type long integer that it converted
        the string to.  No errors are flagged on the atol call.  If the
        string is not numeric, the function atol returns 0.


        Related Functions

        See also the atof, atoi, atou, and strtol functions.


        Example

        /* Program test for the atol() function */

        #include <stdio.h>
        #include <math.h>




        DG/UX 4.00                                                 Page 1
               Licensed material--property of copyright holder(s)





                                                                 atol(3C)



        long    result, atol();
        long    i = 1;

        main(argc, argv)
        int     argc;
        char    *argv[];
        {
            while (i < argc) {
                printf("The result from %s is %ld.\n", argv[i],
                       result = atol(argv[i]));
                i++;
            }
        }

        If you call the program test with the input numbers

        2001
        -2001
        2001
        20-01
        MM1

        you generate the output

        The result from 2001 is 2001.
        The result from -2001 is -2001.
        The result from 2001 is 2001.
        The result from 20-01 is 20.
        The result from MM1 is 0.

























        DG/UX 4.00                                                 Page 2
               Licensed material--property of copyright holder(s)



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