- C 标准库
- C 库 - 首页
- C 库 - <assert.h>
- C 库 - <complex.h>
- C 库 - <ctype.h>
- C 库 - <errno.h>
- C 库 - <fenv.h>
- C 库 - <float.h>
- C 库 - <inttypes.h>
- C 库 - <iso646.h>
- C 库 - <limits.h>
- C 库 - <locale.h>
- C 库 - <math.h>
- C 库 - <setjmp.h>
- C 库 - <signal.h>
- C 库 - <stdalign.h>
- C 库 - <stdarg.h>
- C 库 - <stdbool.h>
- C 库 - <stddef.h>
- C 库 - <stdio.h>
- C 库 - <stdlib.h>
- C 库 - <string.h>
- C 库 - <tgmath.h>
- C 库 - <time.h>
- C 库 - <wctype.h>
- C 标准库资源
- C 库 - 快速指南
- C 库 - 有用资源
- C 库 - 讨论
C 库 - iswctype() 函数
C 的wctype库iswctype()函数用于检查给定的宽字符是否具有某些属性,例如字母、数字、字母数字、可打印字符、图形字符等。
语法
以下是iswctype()函数的C库语法:
int iswctype( wint_t wc, wctype_t desc );
参数
此函数接受以下参数:
-
wc − 一个类型为'wint_t'的宽字符,需要进行检查。
-
desc − 类型为'wint_t'的描述符,指定要检查wc所属的字符类别。 通过调用 "wctype()" 获取。
返回值
如果wc(宽字符)具有“desc”指定的属性,则此函数返回非零值;否则返回零。
示例
以下是一个基本的C程序,用于演示iswctype()的使用。
#include <wchar.h>
#include <wctype.h>
#include <stdio.h>
int main() {
// Wide character to check
wchar_t wc = L'A';
// Descriptor for alphabetic characters
wctype_t desc = wctype("alpha");
if (iswctype(wc, desc)) {
wprintf(L"%lc is an alphabetic character.\n", wc);
} else {
wprintf(L"%lc is not an alphabetic character.\n", wc);
}
return 0;
}
输出
以下是输出:
A is an alphabetic character.
示例 1
让我们创建另一个C示例,并使用iswctype()来检查宽字符是否为字母数字字符。
#include <wchar.h>
#include <wctype.h>
#include <stdio.h>
int main() {
// Wide character string to check
wchar_t str[] = L"Tutorialspoint 500081";
// Descriptor for alphanumeric characters
wctype_t desc = wctype("alnum");
// Loop through each character in the string
for (size_t i = 0; str[i] != L'\0'; ++i) {
// Check if the character is alphanumeric
if (iswctype(str[i], desc)) {
wprintf(L"%lc is an alphanumeric character.\n", str[i]);
} else {
wprintf(L"%lc is not an alphanumeric character.\n", str[i]);
}
}
return 0;
}
输出
以下是输出:
T is an alphanumeric character. u is an alphanumeric character. t is an alphanumeric character. o is an alphanumeric character. r is an alphanumeric character. i is an alphanumeric character. a is an alphanumeric character. l is an alphanumeric character. s is an alphanumeric character. p is an alphanumeric character. o is an alphanumeric character. i is an alphanumeric character. n is an alphanumeric character. t is an alphanumeric character. is not an alphanumeric character. 5 is an alphanumeric character. 0 is an alphanumeric character. 0 is an alphanumeric character. 0 is an alphanumeric character. 8 is an alphanumeric character. 1 is an alphanumeric character.
示例 2
下面的示例检查宽字符wc是否为标点符号字符并打印。
#include <wchar.h>
#include <wctype.h>
#include <stdio.h>
int main()
{
wchar_t wc = L'#';
// checks if the character is a punctuation
if (iswctype(wc, wctype("punct")))
wprintf(L"%lc is a punctuation\n", wc);
else
wprintf(L"%lc is not a punctuation\n", wc);
return 0;
}
输出
以下是输出:
# is a punctuation
c_library_wctype_h.htm
广告