#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>

/* 
 * This test uses wcswcs() to find the occurrence of each
 * subwide-character string, string1 and string2, within
 * the main wide-character string, lookin.                
 */

#define BUF_SIZE 50

int main(void) {
  static char lookin[] = "that this is a test was at the end";
  char string1[] = "this",
       string2[] = "the end";

  wchar_t buffer[BUF_SIZE],
          input_buffer[BUF_SIZE];

  /* 
   * Convert lookin to wide-character format.
   * Buffer and print it out.
   */
  if (mbstowcs(buffer, lookin, BUF_SIZE) == (size_t)-1) {
      perror("mbstowcs");
      exit(-1);
  }

  printf("Buffer to look in: %S\n", buffer);

  /* 
   * Convert string1 to wide-character format and use
   * wcswcs() to locate it within buffer              
   */
  if (mbstowcs(input_buffer, string1, BUF_SIZE) == (size_t)-1) {
      perror("mbstowcs");
      exit(-1);
  }

  printf("this: %S\n", wcswcs(buffer, input_buffer));

  /* 
   * Convert string2 to wide-character format and use
   * wcswcs() to locate it within buffer
   */
  if (mbstowcs(input_buffer, string2, BUF_SIZE) == (size_t)-1) {
      perror("mbstowcs");
      exit(-1);
  }
  
  printf("the end: %S\n", wcswcs(buffer, input_buffer));
  exit(1);
}