
- 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 庫 - iswprint() 函式
C 的wctype庫iswprint()函式用於檢查給定的寬字元(型別為wint_t)是否可以列印。
可列印字元包括數字 (0123456789)、大寫字母 (ABCDEFGHIJKLMNOPQRSTUVWXYZ)、小寫字母 (abcdefghijklmnopqrstuvwxyz)、標點符號 (!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)、空格或當前 C 語言區域設定中特有的任何可列印字元。
此函式包括所有圖形字元和空格字元。
語法
以下是iswprint()函式的C庫語法:
int iswprint( wint_t ch );
引數
此函式接受單個引數:
-
ch − 一個待檢查的型別為'wint_t'的寬字元。
返回值
如果寬字元可列印,則此函式返回非零值;否則返回零。
示例 1
以下是一個基本的 C 程式,用於演示 iswprint() 的用法。
#include <locale.h> #include <stdio.h> #include <wchar.h> #include <wctype.h> int main(void) { // Set the locale to "en_US.utf8" setlocale(LC_ALL, "en_US.utf8"); wchar_t space = L' '; // Check if the character is printable int res = iswprint(space); if (res) { printf("The character ' ' is a printable character.\n"); } else { printf("The character ' ' is not a printable character.\n"); } return 0; }
輸出
以下是輸出:
The character ' ' is a printable character.
示例 2
讓我們建立另一個 C 示例,並使用 iswprint() 來識別寬字元集中的可列印字元。
#include <locale.h> #include <stdio.h> #include <wchar.h> #include <wctype.h> int main(void) { // "en_US.utf8" to handle Unicode characters setlocale(LC_ALL, "en_US.utf8"); // Array of wide characters including // printable and non-printable characters wchar_t character[] = {L'A', L' ', L'\n', L'\u2028'}; size_t num_char = sizeof(character) / sizeof(character[0]); // Check and print if a character is printable character or not printf("Checking printable characters:\n"); for (size_t i = 0; i < num_char; ++i) { wchar_t ch = character[i]; printf("Character '%lc' (%#x) is %s printable char\n", ch, ch, iswprint(ch) ? "a" : "not a"); } return 0; }
輸出
以下是輸出:
Checking printable characters: Character 'A' (0x41) is a printable char Character ' ' (0x20) is a printable char Character ' ' (0xa) is not a printable char Character ' ' (0x2028) is not a printable char
示例 3
下面的 C 示例使用 iswprint() 來檢查特殊字元在 Unicode 區域設定中是否為可列印字元。
#include <locale.h> #include <stdio.h> #include <wchar.h> #include <wctype.h> int main(void) { // "en_US.utf8" to handle Unicode characters setlocale(LC_ALL, "en_US.utf8"); wchar_t spclChar[] = {L'@', L'#', L'$', L'%'}; size_t num_char = sizeof(spclChar) / sizeof(spclChar[0]); // Check and print if a character is printable character or not printf("Checking printable characters:\n"); for (size_t i = 0; i < num_char; ++i) { wchar_t ch = spclChar[i]; printf("Char '%lc' (%#x) is %s printable char\n", ch, ch, iswprint(ch) ? "a" : "not a"); } return 0; }
輸出
以下是輸出:
Checking printable characters: Char '@' (0x40) is a printable char Char '#' (0x23) is a printable char Char '$' (0x24) is a printable char Char '%' (0x25) is a printable char
c_library_wctype_h.htm
廣告