#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <string.h>

/* 
 * This program checks the wcschr function by incrementally
 * going through a string that ascends to the middle and
 * then descends towards the end.
 */

#define BUFF_SIZE 50

int main(void) {
   int i;
   wchar_t s1buf[BUFF_SIZE];
   wchar_t *status;

   /* Initialize the buffer */
   if (mbstowcs(s1buf, "abcdefghijkl lkjihgfedcba", BUFF_SIZE) == (size_t)-1) {
	   perror("mbstowcs");
	   exit(-1);
   }                        */

   for (i = 0; (s1buf[i] != '\0') && (s1buf[i] != ' '); i++) {
	   status = wcschr(s1buf, s1buf[i]);
	   /* Check for pointer to leftmost character -test 1. */
	   if (status != &s1buf[i]) {
		   printf("Error in wcschr\n");
		   exit(-1);
	   }
   }

   printf("Program completed successfully\n");
   return (0);
}
