C examples for stdlib.h:strtoull
function
<cstdlib> <stdlib.h>
Convert string to unsigned long long integer return as a value of type unsigned long long int.
unsigned long long int strtoull (const char* str, char** endptr, int base);
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) |
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.
#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; }