C 库 - iswlower() 函数
C wctype 库中的 iswlower() 函数用于检查给定的宽字符(用 wint_t 表示)是否为小写字母,例如"abcdefghijklmnopqrstuvwxyz"或当前语言环境指定的任何小写字母。
此函数可用于字符验证、大小写转换、字符串处理或标记化和解析。
语法
以下是 iswlower() 函数的 C 库语法 -
int iswlower( wint_t ch )
参数
此函数接受单个参数 -
-
ch - 需要检查的是类型为"wint_t"的宽字符。
返回值
如果宽字符为小写字母,则此函数返回非零值,否则返回零。
示例 1
以下是演示 iswlower() 函数用法的基本 C 语言示例。
#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. ", wc); } else { wprintf(L"The character '%lc' is not a lowercase letter. ", 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"; // 遍历宽字符串中的每个字符 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; // 遍历宽字符串中的每个字符 for (int i = 0; str[i] != L'\0'; i++) { if (iswlower(str[i])) { lowercaseCount++; } } // 打印结果 wprintf(L"The wide string \"%ls\" contains %d lowercase letter(s). ", str, lowercaseCount); return 0; }
输出
以下是输出 -
The wide string "Hello, tutorialspoint India" contains 22 lowercase letter(s).