Converts the initial portion of the wide-character string pointed to by nptr to an unsigned long integer.
#include <wchar.h> unsigned long int wcstoul (const wchar_t *nptr, wchar_t **endptr, int base);Function Variants This function also has variants named _wcstoul32 and _wcstoul64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.8 for more information on using pointer-size-specific functions.
If base is 16, leading zeros after the optional sign are ignored, and 0x or 0X is ignored.
If base is 0, the sequence of characters is interpreted by the same rules used to interpret an integer constant: after the optional sign, a leading 0 indicates octal conversion, a leading 0x or 0X indicates hexadecimal conversion, and any other combination of leading characters indicates decimal conversion.
x | The converted value. |
0 | Indicates that the string starts with an unrecognized wide character or that the value for base is invalid. If the string starts with an unrecognized wide character, *endptr is set to nptr. The function sets errno to EINVAL. |
ULONG_ MAX | Indicates that the converted value would cause an overflow. The function sets errno to ERANGE. |
#include <stdlib.h> #include <stdio.h> #include <wchar.h> #include <errno.h> #include <limits.h> /* This test calls wcstoul() to convert a string to an unsigned long */ /* integer. The resulting integer and any characters that could not */ /* be converted are output. */ #define MAX_STRING 128 main() { int base=10, errno; char *input_string="1234.56"; wchar_t string_array[MAX_STRING], *ptr; size_t size; unsigned long int val; printf("base = [%d]\n",base); printf("String to convert = %s\n",input_string); if ((size = mbstowcs(string_array,input_string,MAX_STRING)) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } printf("wchar_t string is = [%S]\n",string_array); errno = 0; val = wcstoul(string_array, &ptr, base); if (errno == 0) { printf("returned unsigned long int from wcstoul = [%u]\n",val); printf("wide char terminating scan(ptr) = [%S]\n\n",ptr); } if (errno == ERANGE) { perror("error value is :"); printf("ULONG_MAX = [%u]\n",ULONG_MAX); printf("wcstoul failed, val = [%d]\n\n",val); } }
Running the example program produces the following result:
base = [10] String to convert = 1234.56 wchar_t string is = [1234.56] returned unsigned long int from wcstoul = [1234] wide char terminating scan(ptr) = [.56]