#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <string.h>

/*
 * This test sets up 2 strings, buffer and w_string, and
 * then uses wcscspn() to calculate the maximum segment
 * of w_string, which consists entirely of characters
 * NOT from buffer.
 */

#define BUFF_SIZE 20
#define STRING_SIZE 50

int main(void) {
	wchar_t buffer[BUFF_SIZE];
	wchar_t w_string[STRING_SIZE];
	size_t result;
	
	/* Initialize the buffer */
	if (mbstowcs(buffer, "abcdefg", BUFF_SIZE) == (size_t)-1) {
		perror("mbstowcs");
		exit(-1);
	}
	
	/* Initialize the string */
	if (mbstowcs(w_string, "jklmabcjklabcdehjklmno", STRING_SIZE) == (size_t)-1) {
		perror("mbstowcs");
		exit(-1);
	}
	
	/* Using wcscspn - work out the largest string in w_string */
	/* which consists entirely of characters NOT from buffer   */
	result = wcscspn(w_string, buffer);
	printf("Longest segment NOT found in w_string is: %d", result);
	return (0);
}
