/************************************************************************ * * * 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. * * * ************************************************************************/ /* wcsrchr_example.c */ #include #include #include #include #define BUFF_SIZE 50 #define STRING_SIZE 6 main() { int i; wchar_t s1buf[BUFF_SIZE], w_string[STRING_SIZE]; wchar_t *status; wchar_t *pbuf = s1buf; /* Initialize the buffer */ if (mbstowcs(s1buf, "hijklabcdefg ytuhijklfedcba", BUFF_SIZE) == -1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* Initialize the string to be searched for */ if (mbstowcs(w_string, "hijkl", STRING_SIZE) == -1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* This program checks the wcsrchr function by searching for the */ /* last occurrence of a string in the buffer s1buf and prints out */ /* the contents of s1buff from the location of the string found. */ status = wcsrchr(s1buf, w_string[0]); /* Check for pointer to start of rightmost character string. */ if (status == pbuf) { printf("Error in wcsrchr\n"); exit(EXIT_FAILURE); } printf("Program completed successfully\n"); printf("String found : [%S]\n", status); }