Format
#include <stdlib.h> long int atol(const char *string);
Language Level: ANSI, POSIX, XPG4
atol converts a character string to a long value.
The input string is a sequence of characters that can be interpreted as a numerical value of the specified return type. The function stops reading the input string at the first character that it cannot recognize as part of a number; this character can be the null character that ends the string.
atol does not recognize decimal points nor exponents. The string argument for this function has the form:
where whitespace consists of the same characters for which the isspace function is true, such as spaces and tabs. atol ignores leading white-space characters. digits is one or more decimal digits.
Return Value
atol returns a long value produced by interpreting the
input characters as a number. The return value is 0L if the
function cannot convert the input to a value of that type. The
return value is undefined in case of overflow.
Example
This example shows how to convert numbers stored as strings to
numerical values using the atol function.
#include <stdio.h> #include <stdlib.h>
int main(void)
{
long l;
char *s;
s = "98854 dollars";
l = atol(s); /* l = 98854 */
printf("atol ( %s ) = %d\n", s, l);
return 0;
/**************************************
The output should be similar to:
atol( 98854 dollars ) = 98854 **************************************/ }
![]()
atof -- Convert Character String to Float
atoi -- Convert Character String to Integer
_atold -- Convert Character Str ing to Long
Double
atoll -- Convert Character String to Long
Long Integer
strtod -- Convert Character String to
Double
strtol -- Convert Character String to Long
Integer
strtold -- Convert String to Long Do uble
<stdlib.h>