atoll Function

Converts a string to a long long integer.




long long atoll(const char *s);


the string to be converted

Return Value

Returns the converted long long integer if successful; otherwise, returns 0.


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.


See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#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