C Data Type Functions - C strtoll

Convert string to long long integer


long long int strtoll (const char* str, char** endptr, int base);


This function has the following parameter.

C-string beginning with the representation of an integral number.
Reference to an object of type char*, whose value is set by the function to the next character in str after the numerical value.
Numerical base (radix) that determines the valid characters and their interpretation. If this is 0, the base used is determined by the format in the sequence.


returns the converted integral number as a long int value.

If no valid conversion could be performed, a zero value is returned ( 0LL).


#include <stdio.h> /* printf, NULL */
#include <stdlib.h> /* strtoll */
/*  www.  j  a  v  a 2 s. co m*/
int main (){
  char szNumbers[] = "1231231235 17b00a12b -01100011010110 0x6fffff";
  char* pEnd;
  long long int lli1, lli2, lli3, lli4;
  lli1 = strtoll (szNumbers, &pEnd, 10);
  lli2 = strtoll (pEnd, &pEnd, 16);
  lli3 = strtoll (pEnd, &pEnd, 2);
  lli4 = strtoll (pEnd, NULL, 0);
  printf ("The decimal equivalents are: %lld, %lld, %lld and %lld.\n", lli1, lli2, lli3, lli4);
  return 0;

The code above generates the following result.