C庫函式 int isprint(int c) 檢查傳遞的字元是否是可列印的。可列印字元一個字元是不是一個控制字元。
以下是 isprint() 函式的宣告。
int isprint(int c);
c -- 這是要檢查的字元。
如果c是一個可列印的字元,這個函式返回一個非零值(true),否則返回零(false)
下面的例子顯示 int isprint(int c) 函式的用法。
#include <stdio.h> #include <ctype.h> int main() { int var1 = 'k'; int var2 = '8'; int var3 = ' '; int var4 = ' '; if( isprint(var1) ) { printf("var1 = |%c| can be printed ", var1 ); } else { printf("var1 = |%c| can't be printed ", var1 ); } if( isprint(var2) ) { printf("var2 = |%c| can be printed ", var2 ); } else { printf("var2 = |%c| can't be printed ", var2 ); } if( isprint(var3) ) { printf("var3 = |%c| can be printed ", var3 ); } else { printf("var3 = |%c| can't be printed ", var3 ); } if( isprint(var4) ) { printf("var4 = |%c| can be printed ", var4 ); } else { printf("var4 = |%c| can't be printed ", var4 ); } return(0); }
讓我們編譯和執行上面的程式,這將產生以下結果:
var1 = |k| can be printed var2 = |8| can be printed var3 = | | can't be printed var4 = | | can be printed