Open In App

iswlower() Function in C

Last Updated : 26 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Syntax of iswlower() function

int iswlower(wint_t ch)

Here, wint_t is a wide integer type used to represent a wide character.

Parameters

  • ch: It is the wide character which we have to check if it is a lowercase character or not.

Return Value

The iswlower() function returns two values as shown below:

  • If the parameter ch is a lowercase character, then a non-zero value is returned.
  • If it is not a lowercase character, then 0 is returned.

Note: The behavior of iswlower() function is Locale-Sensitive means it’s behavior can be affected by the current locale setting, Hence if the locale is set using std::locale then it may affect the behavior of wide character functions because it performs the check based on the rules of the current C locale.

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;
}


Output

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;
}


Output

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"GeeksforGeeks";
 
    // 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 “geeksforgeeks”) and prints a message only if the character is found to be a lowercase letter, using the iswlower() function.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads