1. 主页
  2. 文档
  3. C语言教程
  4. C语言预处理器
  5. C 库函数-isgraph()

C 库函数-isgraph()

C 库函数isgraph()检查字符是否为图形字符。
已知具有图形表示的字符图形字符。例如: ‘:’ ‘;’ “?” ‘@’ 等等。

语法 –

#include <ctype.h>
int isgraph(int ch);

返回值 –如果 ch 是除空格以外的任何可打印字符,则函数返回非零,否则返回 0。

对于 ASCII 环境,可打印字符的范围是0X210X7E

代码 –

// code to check graphical character
#include <stdio.h>
#include <ctype.h>

int main()
{
char var1 = 'g';
char var2 = ' ';
char var3 = '1';

if (isgraph(var1)) 
printf("var1 = |%c| can be printed\n", var1);
else 
printf("var1 = |%c| can't be printed\n", var1);

if (isgraph(var2)) 
printf("var2 = |%c| can be printed\n", var2);
else 
printf("var2 = |%c| can't be printed\n", var2);

if (isgraph(var3)) 
printf("var3 = |%c| can be printed\n", var3);
else 
printf("var3 = |%c| can't be printed\n", var3);

return (0);
}

输出 –

var1 = |g| can be printed
var2 = | | can't be printed
var3 = |1| can be printed

代码 –

// code to print all Graphical Characters
#include <stdio.h>
#include <ctype.h>

int main()
{ 
int i;
printf("In C programming All graphic "
"characters are: \n");

for (i = 0; i <= 127; ++i) 
if (isgraph(i) != 0)
printf("%c ", i); 

return 0;
}

输出 –

在 C 编程中所有图形字符是: 
!" # $ % & ' ( ) * +, - . / 0 1 2 3 4 5 6 7 8 9
: ; ? @ABCDEFGHIJKLMNOPQRSTU
 VWXYZ [ \ ] ^ _ ` abcdefghijklmn
 opqrstuvwxyz { | } ~

 

这篇文章对您有用吗?