C Data Type Functions - C strtoull






Convert string to unsigned long long integer

Prototype

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

Parameter

This function has the following parameter.

str
C-string
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. This parameter can also be a null pointer, in which case it is not used.
base
Numerical base (radix) that determines the valid characters. If this is 0, the base used is determined by the format in the sequence.

Return

returns the converted integral number as an unsigned long long int value.

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





Example


#include <stdio.h> /* printf, NULL */
#include <stdlib.h> /* strtoull */
//from  www . j a va  2s  .  c  o m
int main (){
  char szNumbers[] = "250 76af00 110001101111010 0x6fffff";
  char * pEnd;
  unsigned long long int ulli1, ulli2, ulli3, ulli4;
  ulli1 = strtoull (szNumbers, &pEnd, 10);
  ulli2 = strtoull (pEnd, &pEnd, 16);
  ulli3 = strtoull (pEnd, &pEnd, 2);
  ulli4 = strtoull (pEnd, NULL, 0);
  printf ("The decimal equivalents are: %llu, %llu, %llu and %llu.\n", ulli1, ulli2, ulli3, ulli4);
  return 0;
} 

The code above generates the following result.