strtoull - C stdlib.h

C examples for stdlib.h:strtoull

Type

function

From


<cstdlib>
<stdlib.h>

Description

Convert string to unsigned long long integer return as a value of type unsigned long long int.

Prototype

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

Parameters

Parameter Description
str C-string representation of an integral number.
endptr type char* set by the function to the next character in str after the numerical value.
base Numerical base (radix)

Return Value

On success, the function returns the converted integral number as an unsigned long long int value.

For non valid conversion, a zero value is returned (0ULL).

For out of the range values, the function returns ULLONG_MAX (defined in <climits>), and errno is set to ERANGE.

Demo Code


#include <stdio.h> /* printf, NULL */
#include <stdlib.h> /* strtoull */

int main ()/*from w  w w. ja  va2s . c om*/
{
  char str[] = "123456792 7b06af00 1010101010101010101010101010 0x6ffdead";
  char * pEnd;
  unsigned long long int ulli1, ulli2, ulli3, ulli4;
  ulli1 = strtoull (str, &pEnd, 10);
  ulli2 = strtoull (pEnd, &pEnd, 16);
  ulli3 = strtoull (pEnd, &pEnd, 2);
  ulli4 = strtoull (pEnd, NULL, 0);
  
  printf ("%llu, %llu, %llu and %llu.\n", ulli1, ulli2, ulli3, ulli4);
  return 0;
}

Related Tutorials