The wcscmp() function is defined in cwchar.h header file. The wcscmp() function is used to compares two null terminating wide string and this comparison is done lexicographically.
Syntax:
int wcscmp(const wchar_t* str1, const wchar_t* str2);
Parameters: This method takes the following two parameters:
- str1: This represents the pointer to the first string to be compare.
- str2: This represents the pointer to the second string to be compare.
Return Value: This method returns:
- Zero: If the str1 and str2 are same.
- Positive value: If the first different character in str1 is greater than the corresponding character in str2.
- Negative value: If the first different character in str1 is less than the corresponding character in str2.
Time Complexity: O(n) where n is the size of the smaller string.
Auxiliary Space: O(1)
Below programs illustrate the above function:-
Example 1:-
cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t str1[] = L"Computer";
wchar_t str2[] = L"Science";
wcout << L"Comparing " << str1 << L" and "
<< str2 << L" = " << wcscmp(str1, str2) << endl;
wcout << L"Comparing " << str2 << L" and "
<< str2 << L" = " << wcscmp(str2, str2) << endl;
wcout << L"Comparing " << str2 << L" and "
<< str1 << L" = " << wcscmp(str2, str1) << endl;
return 0;
}
|
Output:Comparing Computer and Science = -1
Comparing Science and Science = 0
Comparing Science and Computer = 1
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!
Last Updated :
26 Jun, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...