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

        #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)

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

            /* Initialize the string to be searched for */

            if (mbstowcs(w_string, "hijkl", STRING_SIZE) == (size_t)-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);

        }

      Running the example produces the following result:

        Program completed successfully
        String found : [hijklfedcba]
Close Help