Format
#include <wchar.h> unsigned long int wcstoul(const wchar_t *nptr, wchar_t **endptr, int base);
Language Level: ANSI, XPG4
wcstoul converts the wide-character string pointed to by nptr
to an unsigned long integer value. nptr points to a
sequence of wide characters that can be interpreted as a
numerical value of type unsigned long int. wcstoul stops reading
the string at the first wide character that it cannot recognize
as part of a number. This character can be the wchar_t null
character at the end of the string. The ending character can also
be the first numeric character greater than or equal to the base.
When you use wcstoul, nptr 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.
In locales other than the "C" locale, additional implementation-defined subject sequence forms may be accepted.
If the subject sequence is empty or does not have the expected form, no conversion is performed and wcstoul stores the value of nptr in the object pointed to by endptr, provided that endptr is not a null pointer.
The behavior of wcstoul is affected by the LC_CTYPE category of the current locale.
Return Value
wcstoul returns the converted unsigned long integer
value. If no conversion could be performed, wcstoul returns 0. If
the correct value is outside the range of representable values,
wcstoul returns ULONG_MAX and sets errno to ERANGE.
If the string nptr points to is empty or does not have the expected form, no conversion is performed, and the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a null pointer.
Example
This example uses wcstoul to convert the string wcs to
an unsigned long integer value.
#include <stdio.h> #include <wchar.h>
#define BASE 2
int main(void)
{
wchar_t *wcs = L"1000e13 camels";
wchar_t *endptr;
unsigned long int answer;
answer = wcstoul(wcs, &endptr, BASE);
printf("The input wide string used: `%ls`\n"
"The unsigned long int produced: %lu\n"
"The substring of the input wide string that was not"
" converted to unsigned long: `%ls`\n", wcs, answer, endptr);
return 0;
/*********************************************************************
The output should be similar to:
The input wide string used: 1000e13 camels
The unsigned long int produced: 8
The substring of the input wide string that was not converted to
unsigned long: e13 camels
*********************************************************************/
}
![]()
strtod -- Convert Character String to
Double
strtol -- Convert Character String to
Long Integer
strtold -- Convert String to Long
Double
wcstod -- Convert Wide-Character
String to Double
wcstol -- Convert Wide-Character to
Long Integer
<wchar.h>