/************************************************************************ * * * Copyright Digital Equipment Corporation 1998. All rights reserved. * * * * Restricted Rights: Use, duplication, or disclosure by the U.S. * * Government is subject to restrictions as set forth in subparagraph * * (c) (1) (ii) of DFARS 252.227-7013, or in FAR 52.227-19, or in FAR * * 52.227-14 Alt. III, as applicable. * * * * This software is proprietary to and embodies the confidential * * technology of Digital Equipment Corporation. Possession, use, or * * copying of this software and media is authorized only pursuant to a * * valid written license from Digital or an authorized sublicensor. * * * ************************************************************************/ /* wcsspn_example.c */ #include #include #include #include /* 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) == -1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* Initialize the string */ if (mbstowcs(w_string, "abcedjklmabcjklabcdehjkl", STRING_SIZE) == -1) { 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); }