Examples of iswlower() in C
Example 1:
The below program demonstrates the use of iswlower() function in C to check if the given wide character is a lowercase character or not.
C
// C program to demonstate the use of iswlower() function #include <stdio.h> #include <wchar.h> #include <wctype.h> int main() { // Defining two wide characters wchar_t ch1 = L 'a' ; wchar_t ch2 = L 'A' ; // Function to check if the wide character // is a lowercase character or not if (iswlower(ch1)) wprintf(L "%lc is a lowercase character " , ch1); else wprintf(L "%lc is not a lowercase character " , ch1); wprintf(L "\n" ); if (iswlower(ch2)) wprintf(L "%lc is a lowercase character " , ch2); else wprintf(L "%lc is not a lowercase character " , ch2); return 0; } |
a is a lowercase character A is not a lowercase character
Explanation: The above program uses the iswlower() function in C to check whether the two wide characters, L’a’ and L’A’ (here L represent that it is a wide character literal of type wchar_t) are lowercase or not. It prints messages accordingly to indicate whether each given character is a lowercase character or not.
Example 2:
Another example to demonstrate the use of iswlower() function in C.
C
// C++ program to demonstrate the use of // iswlower() function #include <stdio.h> #include <wchar.h> #include <wctype.h> int main() { // Defining two wide characters wint_t ch1 = L 'q' ; wint_t ch2 = L '?' ; // Function to check if the given wide character is a // lowercase character or not if (iswlower(ch1)) wprintf(L "%lc is a lowercase character\n" , ch1); else wprintf(L "%lc is not a lowercase character\n" , ch1); if (iswlower(ch2)) wprintf(L "%lc is a lowercase character\n" , ch2); else wprintf(L "%lc is not a lowercase character\n" , ch2); return 0; } |
q is a lowercase character ? is not a lowercase character
Example 3:
The below programs demonstrate the use of iswlower() function in a loop to process each character in a wide string.
C
#include <stdio.h> #include <wchar.h> #include <wctype.h> int main() { // Initializing wide string wchar_t myStr[] = L "w3wiki" ; // Iterate through each character of the wide string for ( int i = 0; myStr[i] != L '\0' ; ++i) { // Check if the character is lowercase or not if (iswlower(myStr[i])) // If lowercase, print it wprintf(L "%lc is a lowercase character.\n" , myStr[i]); } return 0; } |
Output
e is a lowercase character. e is a lowercase character. k is a lowercase character. s is a lowercase character. f is a lowercase character. o is a lowercase character. r is a lowercase character. e is a lowercase character. e is a lowercase character. k is a lowercase character. s is a lowercase character.
Explanation: The above program iterates through each character of myStr (wide string “w3wiki”) and prints a message only if the character is found to be a lowercase letter, using the iswlower() function.
iswlower() Function in C
The iswlower() is a built-in function in C that checks whether the given wide character is a lowercase character or not.
iswlower() function is defined inside the <wctype.h> in C.