Format
#include <stdlib.h> unsigned long int strtoul(const char *string1, char **string2, int base);
Language Level: ANSI, XPG4
strtoul converts a character string to an unsigned long integer
value. The input string1 is a sequence of characters
that can be interpreted as a numerical value of the type unsigned
long int. strtoul stops reading the string at the first character
that it cannot recognize as part of a number. This character can
be the first numeric character greater than or equal to the base.
strtoul sets string2 to point to the resulting output
string if a conversion is performed, and provided that string2
is not a NULL pointer.
When you use strtoul, on OS/2 and Windows, string1 should point to a string with the following form:

If base is in the range of 2 through 36, it becomes the base of the number. If base is 0, the prefix determines the base (8, 16, or 10): the prefix 0 means base 8 (octal); the prefix 0x or 0X means base 16 (hexadecimal); using any other digit without a prefix means decimal.
Return Value
strtoul returns the value represented in the string, or
0 if no conversion could be performed. For an overflow, strtoul
returns ULONG_MAX and sets errno to ERANGE. If base is
not a valid number, strtoul sets errno to EDOM.
Example
This example converts the string to an unsigned long
value. It prints out the converted value and the substring that
stopped the conversion.
#include <stdio.h> #include <stdlib.h>
#define BASE 2
int main(void)
{
char *string, *stopstring;
unsigned long ul;
string = "1000e13 e";
printf("string = %s\n", string);
ul = strtoul(string, &stopstring, BASE);
printf(" strtoul = %ld (base %d)\n", ul, BASE);
printf(" Stopped scan at %s\n\n", stopstring);
return 0;
/***********************************************
The output should be:
string = 1000e13 e
strtoul = 8 (base 2)
Stopped scan at e13 e
***********************************************/
}
![]()
atof -- Convert Character String to Float
atoi -- Convert Character String to
Integer
atol -- Convert Character String to Long
Integer
_atold -- Convert Character String to
Long Double
strtod -- Convert Character String to
Double
strtol -- Convert Character String to
Long Integer
strtold -- Convert Character String to
Long Double
strtoll -- Convert Character String to
Long Long Integer
strtoull -- Convert String Segment to
Unsigned Long Long Integer
_ultoa -- Convert Unsigned Long Integer
to String
wcstod -- Convert Wide-Character
String to Double
wcstol -- Convert Wide-Character to
Long Integer
wcstoul -- Convert Wide-Character
String to Unsigned Long
<stdlib.h>