wcsncmp() function in C/C++
The wcsncmp() function in C/C++ compare characters of two wide strings. The comparison is done lexicographically. This function takes three arguments lhs, rhs and count. It compares the contents of lhs and rhs lexicographically upto a maximum of count wide characters.
Note: The behaviour of wcsncmp() is undefined if either of lhs or rhs do not point to null terminated wide strings.
int wcsncmp( const wchar_t* lhs, const wchar_t* rhs, size_t count )
Parameter :The function accepts three mandatory parameters which are described below:
- lhs : String to be compared
- rhs : String to be compared
- count : Maximum number of characters to compare
Return value: The function returns three value as below:
- Positive value: if the first differing character in lhs is greater than the corresponding character in rhs.
- Negative value: if the first differing character in lhs is less than the corresponding character in rhs.
- Zero: if the characters compared in both the strings form the same string.
Below programs illustrate the above function:
Program 1 :
First 4 characters of are same geekGgeek precedes geekforgeeks
Program 2 :
First 5 characters of are same First 8 characters of are same