VMS Help  —  CRTL  wcsspn  Example
        #include <stdlib.h>
        #include <stdio.h>
        #include <wchar.h>
        #include <string.h>

        /* This test sets up 2 strings, buffer and w_string. It */
        /* then uses wcsspn() to calculate the maximum segment  */
        /* of w_string that consists entirely of characters     */
        /* from buffer.                                         */

        #define BUFF_SIZE 20
        #define STRING_SIZE 50

        main()
        {
            wchar_t buffer[BUFF_SIZE];
            wchar_t w_string[STRING_SIZE];
            size_t result;

            /* Initialize the buffer */

            if (mbstowcs(buffer, "abcdefg", BUFF_SIZE) == (size_t)-1) {

                perror("mbstowcs");
                exit(EXIT_FAILURE);
            }

            /* Initialize the string */

            if (mbstowcs(w_
 string, "abcedjklmabcjklabcdehjkl", STRING_SIZE)

                perror("mbstowcs");
                exit(EXIT_FAILURE);
            }

        /* Using wcsspn - work out the largest string in w_string */
        /* that consists entirely of characters from buffer       */

            result = wcsspn(w_string, buffer);
            printf("Longest segment found in w_
 string is: %d", result);

        }

    Running the example program produces the following result:

    Longest segment found in w_string is: 5
Close Help