C library - iswupper() function



The C wctype library iswupper() function is used to check whether a given wide character (represented by wint_t) is a uppercase letter or not, i.e. one of "ABCDEFGHIJKLMNOPQRSTUVWXYZ" or any uppercase 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 iswupper() function −

int iswupper( 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 an uppercase letter, zero otherwise.

Example 1

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

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

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

Output

Following is the output −

The character 'A' is a uppercase letter.

Example 2

We create a c program and using the iswupper() to count the number of uppercase letter from the given wide character.

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

int main() {
   // Define a wide string with mixed characters
   wchar_t str[] = L"Hello, tutorialspoint India";
   int uppercaseCount = 0;

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

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

   return 0;
}

Output

Following is the output −

The wide string "Hello, tutorialspoint India" contains 2 uppercase letter(s).

Example 3

The following is the another example, we print the uppercase letter when we get the uppercase letter in 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 (iswupper(str[i])) {
         wprintf(L"%lc", str[i]);
      }
   }
   return 0;
}

Output

Following is the output −

HI
c_library_wctype_h.htm
Advertisements