atol(3) CLIX atol(3)
NAME
atol - Converts a string to a long integer
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
long atol(
char *str );
PARAMETERS
str Specifies a pointer to a character string.
DESCRIPTION
The atol() function returns as a long base 10 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 in isspace(3)) are ignored.
Truncation from long to int can, of course, take place upon assignment or
by an explicit cast.
Except for its behavior in the event of an error, the atol(str) function
is equivalent to strtol(str, (char **)NULL, 10).
EXAMPLES
The following uses atol() to convert a string into a long:
main(argc,argv)
int argc;
char **argv;
{
long number; /*Type is long.*/
char string[100]; /*Give input string enough space!"*/
printf("Enter a string: "); /*Prompt*/
scanf("%s",string); /*Get user input, say "589317.476adico"...*/
number=atol(string); /*Convert user input into long (589317)*/
printf("The number is %i.0\n", number); /*Print it to stdout.*/
}
RETURN VALUES
If a correct value causes overflow, LONG_MAX or LONG_MIN (as defined in
<limits.h>) is returned (according to the sign of the value), and errno is
2/94 - Intergraph Corporation 1
atol(3) CLIX atol(3)
set to ERANGE.
Otherwise, the long integer representation of str is returned.
ERRORS
[ERANGE] No conversion was possible, or the conversion results in an
overflow.
RELATED INFORMATION
Functions: atoi(3), atof(3), isspace(3), ctype(3), scanf(3), strtod(3),
strtol(3), strtoul(3)
2 Intergraph Corporation - 2/94