C 庫 - iswlower() 函式



C 的wctypeiswlower() 函式用於檢查給定的寬字元(由 wint_t 表示)是否為小寫字母,即“abcdefghijklmnopqrstuvwxyz”中的一個,或當前區域設定特有的任何小寫字母。

此函式可用於字元驗證、大小寫轉換、字串處理或標記化和解析。

語法

以下是 iswlower() 函式的 C 庫語法:

int iswlower( wint_t ch )

引數

此函式接受一個引數:

  • ch − 一個待檢查的型別為 'wint_t' 的寬字元。

返回值

如果寬字元是小寫字母,則此函式返回非零值;否則返回零。

示例 1

以下是一個基本的 C 示例,演示了 iswlower() 函式的使用。

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

輸出

以下是輸出:

The character 'a' is a lowercase letter.

示例 2

在此示例中,我們使用 iswlower() 列印給定寬字元中的所有小寫字母。

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

輸出

以下是輸出:

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

示例 3

我們建立一個 C 程式來計算給定寬字元中小寫字母的數量。

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

輸出

以下是輸出:

The wide string "Hello, tutorialspoint India" contains 22 lowercase letter(s).
c_library_wctype_h.htm
廣告
© . All rights reserved.