Converts a string to a long long
integer.
Include
<stdlib.h>
Prototype
long long atol(const char *s);
Argument
Return Value
Returns the converted long long
integer if successful;
otherwise, returns 0.
Remarks
The number may consist of the following:
[whitespace] [sign] digits
Optional whitespace followed by an optional sign, then a sequence of one or
more digits. The conversion stops when the first unrecognized character is reached. The
conversion is equivalent to (int) strtoll(s, (char **)NULL, 10)
, except
it does no error checking, so errno
will not be set.
Example
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char a[] = " -123456";
char b[] = "2Number";
long long x;
x = atoll(a);
printf("String = \"%s\" int = %lld\n", a, x);
x = atoll(b);
printf("String = \"%s\" int = %lld\n", b, x);
}
Example Output
String = " -123456" int = -123456
String = "2Number" int = 2