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