C library - iswlower() function



The C wctype library iswlower() function is used to check whether a given wide character (represented by wint_t) is a lowercase letter or not, i.e. one of "abcdefghijklmnopqrstuvwxyz" or any lowercase letter specific to the current locale.

This function can be useful for character validation, case conversion, string processing, or tokenization and parsing.

Syntax

Following is the C library syntax of iswlower() function −

int iswlower( wint_t ch )

Parameters

This function accepts a single parameter −

  • ch − It is a wide character of type 'wint_t' to be checked.

Return Value

This function returns Non-zero value if the wide character is a lowercase letter, zero otherwise.

Example 1

The following is the basic c example that demonstrate the use of iswlower() function.

#include <stdio.h>
#include <wctype.h>
#include <wchar.h>

int main() {
   wchar_t wc = L'a';
   if (iswlower(wc)) {
      wprintf(L"The character '%lc' is a lowercase letter.\n", wc);
   } else {
      wprintf(L"The character '%lc' is not a lowercase letter.\n", wc);
   }
   return 0;
}

Output

Following is the output −

The character 'a' is a lowercase letter.

Example 2

In this example, we use iswlower() to print the all lowercase from the given wide character.

#include <stdio.h>
#include <wctype.h>
#include <wchar.h>

int main() {
   wchar_t str[] = L"Hello, tutorialspoint India";

   // Iterate over each character in the wide string
   for (int i = 0; str[i] != L'\0'; i++) {
      if (iswlower(str[i])) {
         wprintf(L"%lc ", str[i]);
      }
   }
   return 0;
}

Output

Following is the output −

e l l o t u t o r i a l s p o i n t n d i a 

Example 3

We create a c program to count the number of lowercase letter in the given wide character.

#include <stdio.h>
#include <wctype.h>
#include <wchar.h>

int main() {
   wchar_t str[] = L"Hello, tutorialspoint India";
   int lowercaseCount= 0;

   // Iterate over each character in the wide string
   for (int i = 0; str[i] != L'\0'; i++) {
      if (iswlower(str[i])) {
         lowercaseCount++;
      }
   }

   // Print the result
   wprintf(L"The wide string \"%ls\" contains %d lowercase letter(s).\n", str, lowercaseCount);

   return 0;
}

Output

Following is the output −

The wide string "Hello, tutorialspoint India" contains 22 lowercase letter(s).
c_library_wctype_h.htm
Advertisements