C examples for stdlib.h:strtoul
function
<cstdlib> <stdlib.h>
Convert string to unsigned long integer return as an value of type unsigned long int.
unsigned long int strtoul (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 int value.
For non valid conversion, a zero value is returned.
For out of the range values, the function returns ULONG_MAX (defined in <climits>), and errno is set to ERANGE.
#include <stdio.h> #include <stdlib.h> int main ()/*from w w w . j a v a 2s .com*/ { char buffer [256]; unsigned long ul; printf ("Enter an unsigned number: "); fgets (buffer, 256, stdin); ul = strtoul (buffer, NULL, 0); printf ("Value entered: %lu. Its double: %lu\n",ul,ul*2); return 0; }