Library /sys$common/syshlp/helplib.hlb  —  CRTL  wcstoul
    Converts the initial portion of the wide-character string pointed
    to by nptr to an unsigned long integer.

    Format

      #include  <wchar.h>

      unsigned long int wcstoul  (const wchar_t *nptr, wchar_t
                                 **endptr, int base);

1  –  Function Variants

    The wcstoul function has variants named _wcstoul32 and _wcstoul64
    for use with 32-bit and 64-bit pointer sizes, respectively.

2  –  Arguments

 nptr

    A pointer to the wide-character string to be converted to an
    unsigned long.

 endptr

    The address of an object where the function can store the address
    of the first unrecognized character encountered in the conversion
    process (the character that follows the last character in the
    string being converted). If endptr is a NULL pointer, the address
    of the first unrecognized character is not retained.

 base

    The value, 2 through 36, to use as the base for the conversion.

    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.

3  –  Description

    The wcstoul function recognizes strings in various formats,
    depending on the value of the base. It ignores any leading
    white-space characters (as defined by the iswspace function)
    in the string. It recognizes an optional plus or minus sign,
    then a sequence of digits or letters that may represent an
    integer constant according to the value of the base. The first
    unrecognized wide character ends the conversion.

4  –  Return Values

    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.

5  –  Example

        #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. wcstoul outputs the resulting    */
        /* integer and any characters that could not be converted. */

        #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]
Close Help