- 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 程式設計資源
- C 程式設計 - 教程
- C - 有用資源
C 庫 - iswalpha() 函式
C 的wctype 庫 iswalpha() 函式用於檢查給定的寬字元(由 wint_t 表示)是否為字母字元,即大寫字母、小寫字母或當前區域設定特有的任何字母字元。
此函式可用於字元驗證、大小寫轉換、密碼驗證、字串處理或標記化和解析。
語法
以下是 iswalpha() 函式的 C 庫語法:
int iswalpha( wint_t ch )
引數
此函式接受一個引數:
-
ch - 它是要檢查的型別為 'wint_t' 的寬字元。
返回值
如果寬字元是字母字元,則此函式返回非零值,否則返回零。
示例 1
以下是演示 iswalpha() 函式用法的基本 C 示例。
#include <wctype.h>
#include <stdio.h>
int main() {
wint_t ch = L'T';
if (iswalpha(ch)) {
printf("The wide character %lc is alphabetic.\n", ch);
} else {
printf("The wide character %lc is not alphabetic.\n", ch);
}
return 0;
}
輸出
以下是輸出:
The wide character T is alphabetic.
示例 2
在這裡,我們使用 iswalpha() 函式列印字母字元。
#include <stdio.h>
#include <wctype.h>
#include <wchar.h>
int main() {
wchar_t wc[] = L"tutorialspoint 500081";
// Iterate over each character in the wide string
for (int i = 0; wc[i] != L'\0'; i++) {
if (iswalpha(wc[i])) {
wprintf(L"%lc", wc[i]);
}
}
return 0;
}
輸出
以下是輸出:
tutorialspoint
示例 3
讓我們建立一個另一個 C 程式來提取並列印寬字元中的字母字元。
#include <stdio.h>
#include <wctype.h>
#include <wchar.h>
int main() {
wchar_t wc[] = L"2006 tutorialspoint India Pvt.Ltd 2024";
wchar_t alphabetic[100];
int index = 0;
// Iterate over each character in the wide string
for (int i = 0; wc[i] != L'\0'; i++) {
if (iswalpha(wc[i])) {
alphabetic[index++] = wc[i];
}
}
// null terminated string
alphabetic[index] = L'\0';
// print the alphabetic character
wprintf(L"The alphabetic characters in the wide string \"%ls\" \n are \"%ls\".\n", wc, alphabetic);
return 0;
}
輸出
以下是輸出:
The alphabetic characters in the wide string "2006 tutorialspoint India Pvt.Ltd 2024" are "tutorialspointIndiaPvtLtd".
c_library_wctype_h.htm
廣告