Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

atol - Convert a string into a whole number (long)

&pagelevel(4)&pagelevel

Definition

#include <stdlib.h>

int atol(const char *s);

atol converts a string to which s points into an integer. The string to be converted may be formatted as follows:

[{ tab | 'BLANK' }...] [+|-] digit ...

All control characters for white space are legal for tab (see definitiona at isspace).

The atol(str) function differs from strtol(str,(char**)NULL) only in error handling. 

Return val.

Integer value of type long int



for strings formatted as described above and representing a numeric value that lies in the permissible range of integers.


0

for strings which do not correspond to the syntax described above.

 

LONG_MAX or LONG_MIN

 


in the case of an overflow, depending on the sign.

Notes

atol() is completely contained in strtol(). However, the function continues to be offered because it is used in many existing applications.
atol also recognizes strings that begin with digits but then end with any character.
atol cuts off the numeric part, converts it according to the above description, and ignores the rest.

Example

The following program converts a string passed in the call (Enter Options) into the corresponding floating-point number.

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
               /* Numbers are passed as a string!!
                  A conversion is required if the
                  numeric value is needed. */
{
   printf("long integer : %ld\n", atol(argv[1]));
   return 0;
}

See also

atof, atoi, atoll, strtod, strtol, strtoll, strtoul, strtoull