/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
/* This is an example of the function wmemcmp(const wchar_t*, const wchar_t*,
   size_t).  This compares the specifed number of characters of two strings.
   If string1 substring < string2 substring, then a negative value is returned.
   If string1 substring = string2 substring, then zero is returned.
   If string1 substring > string2 substring, then a positive value is returned.
*/
#include <wchar.h>
#include <stdlib.h>

int main() {
    const char *line, *line2;
    wchar_t str1[100], str2[100];
    size_t count;
    int retval,len1,len2;
    count = 6;
    line = "hellohello";
    line2 = "hello";
    len1 = strlen(line);
    len2 = strlen(line2);

    mbstowcs(str1, line, len1);
    mbstowcs(str2, line2,len2);
    retval = wmemcmp(str1, str2, count);
    if(retval != NULL) {
    	fputs("String1: ", stdout);
    	fputws(str1, stdout);
    	fputs("\nString2: ", stdout);
    	fputws(str2, stdout);
    	printf("\nNumber of characters to compare: %d\n", count);
    	if(retval > 0)
            printf("String1 is greater than String2\n");
    	else if(retval == 0)
            printf("String1 is identical to String2\n");
    	else if(retval < 0)
            printf("String1 is less than String2\n");
    	else 
            printf("Error!\n");
    	printf("wmemcmp(str1,str2,count) = %d\n", retval);
    }
    else
        printf("Error\n");
}

