Introduction
Everyone in the world must have done comparison at least once or I say everyday. Similar to that the wcscmp() function does it purpose is comparison of two strings if you want to learn how then checkout the article which covers the implementation of wcscmp() method In C++, The wcscmp() function in C++ compares two null terminating wide strings. The comparison is done lexicographically. It is defined within <cwchar> header file.
There is a popular quote “Don’t talk, just show me the code!!” abiding by the words let see the implementation of the wcscmp() in C++.
Also see, Literals in C, Fibonacci Series in C++
BreakDown of wcscmp() method
The section discusses the detailed breakdown of the wcscmp() method in C++. It includes discussion of declaring the prototype, parameters of wcscmp() and return value of the wcscat() method.
Prototype declaration wcscmp()
int wcscmp( const wchar_t* lhs, const wchar_t* rhs );
The lhs and rhs inputs are sent to the wcscmp() method. It lexicographically compares the contents of lhs and rhs. The difference between the first pairs of characters that differ in lhs and rhs determines the result's sign.
If either lhs or rhs do not point to null terminated wide strings, the behaviour of wcscmp() is unknown.
Parameters of wcscmp()
lhs: Pointer to the wide string to compare that is null terminated.
rhs: Pointer to the wide string to compare that is null ended.
Return value of wcscmp()
The method wcscmp() returns:
1. If the first difference character in lhs is bigger than the equivalent character in rhs, the value is positive.
2. If the first dissimilar character in lhs is smaller than the corresponding character in rhs, the value is negative.
3. If the lhs and rhs are equal, the result is 0.