C Programming/C Reference/wchar.h/wcscmp

From Wikibooks, open books for an open world
Jump to: navigation, search

In C language ,the function wcscmp is included in header file wchar.h wcscmp is similar to strcmp i.e it is used to compare two strings.but the function wcscmp is used to compare wide character strings. If two wide character strings say s1 and s2 are to be compared. Then function wcscmp returns positive integer if s1 is greater than s2. It returns negative integer if string s2 is greater than s1. if two wide character strings i.e s1 and s2 are same then function returns 0.

syntax[edit]

#include <wchar.h>
      int wcscmp(const wchar_t *s1, const wchar_t *s2);

Sample program which uses function wcsncmp[edit]

#include <stdio.h>
#include <wchar.h>
int main() {
        wchar_t string1[] = L"char";
        wchar_t string2[] = L"character";
        int difference;
 
        difference = wcscmp( string1, string2 );
        if ( difference == 0 )
                printf( " Both strings are same"  );
        else {
                if ( difference < 0 )
                        printf( " char is less than character\n" );
                else
                        printf(" char is greater than character\n" );
        }
        return 0;
}

Output of program will be 'char is less than character '
as value of difference is negative.

See also[edit]