#include <string.h>
#include <locale.h>
#include <stdlib.h>

/*
 * The following example uses the wcsspn subroutine to determine
 * the number of wide characters in the initial segment of a wide
 * character string segment:
 */
int main(int argc, char **argv) {
    wchar_t pwcs1[128] = L"Hello World!",
            pwcs2[128] = L"Hello";
    size_t count;
 
    setlocale(LC_ALL, "");
    /*
     *  Let pwcs1 point to a wide character null terminated string.
     *  Let pwcs2 be initialized to the wide character string
     *  that contains wide characters to search for.
     */
    count = wcsspn(pwcs1, pwcs2);
    /*
     *  count contains the length of the segment.
     */
    printf("Length of the segment: %z\n", count);
    return (0);
}
 