C Data Type Functions - C strtoll






Convert string to long long integer

Prototype

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

Parameter

This function has the following parameter.

str
C-string beginning with the representation of an integral number.
endptr
Reference to an object of type char*, whose value is set by the function to the next character in str after the numerical value.
base
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.

Return

returns the converted integral number as a long int value.

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

Example


#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.