Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function - isgraph()

C Library Function - isgraph()


C Standard Library - <ctype.h> C Standard Library -


Description

C Library Function int isgraph(int c) Check whether the passed character has a graphical representation.

Characters with a graphical representation are all printable characters except whitespace characters (such as ' ').

Declaration

Below is the declaration of the isgraph() function.



int isgraph(int c);

Parameters

Return Value

If c has a graphical representation, the function returns a nonzero value; otherwise, it returns 0.

Example

The following example demonstrates the use of the isgraph() function.

Example

#include

<

stdio.h

#include

<

ctype.h

int

main

(

)

{

int

var1

= '

3

';

int

var2

= '

m

';

int

var3

= ' ';

if

(

isgraph

(

var1

)

)

{

printf

(

"

var1 = |%c| is printable

\

n

"

,

var1

)

;

}

else

{

printf

(

"

var1 = |%c| is not printable

\

n

"

,

var1

)

;

}

if

(

isgraph

(

var2

)

)

{

printf

(

"

var2 = |%c| is printable

\

n

"

,

var2

)

;

}

else

{

printf

(

"

var2 = |%c| is not printable

\

n

"

,

var2

)

;

}

if

(

isgraph

(

var3

)

)

{

printf

(

"

var3 = |%c| is printable

\

n

"

,

var3

)

;

}

else

{

printf

(

"

var3 = |%c| is not printable

\

n

"

,

var3

)

;

}

return

(

0

)

;

}

Let's compile and run the above program, which will produce the following result:



var1 = |3| 是可打印的

var2 = |m| 是可打印的

var3 = | | 是不可打印的

The following example prints all graphical characters:

Example

#include

<

stdio.h

#include

<

ctype.h

int

main

(

)

{

int

i

;

printf

(

"

All graphical characters in C:

\

n

"

)

;

for

(

i

=

0

;

i

<=

127

;++

i

)

{

if

(

isgraph

(

i

)

!=

0

)

printf

(

"

%c

"

,

i

)

;

}

return

0

;

}

Let's compile and run the above program, which will produce the following result:

C 语言中所有图形字符: 

! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~


C Standard Library - <ctype.h> C Standard Library -