isprint() - C函數
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