/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
/* This is an example of the function wcsncmp(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() { 
    char *line, *line2;
    wchar_t str1[100], str2[100];        
    size_t count;
    int retval,len1,len2;
    count = 5;
    line = "hellohello";
    line2 = "hello";
    len1 = strlen(line);
    len2 = strlen(line2);
 
    mbstowcs(str1, line, len1);
    mbstowcs(str2, line2,len2);
    fputs("String1: ", stdout);
    fputws(str1, stdout);
    fputs("\nString2: ", stdout);
    fputws(str2, stdout);
    printf("\nNumber of characters to compare: %d\n", count);  
    retval = wcsncmp(str1, str2, 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("wcsncmp(str1,str2,count) = %d\n", retval);
}

