1. So, what is the isgraph function in C and how to use it?
The isgraph
function in C programming language tests if a character has a graphic representation. A graphic representation is, in turn, synonymous to visual display. So, if a character can be displayed on the screen, then it is considered to be graphically representable and the return value of isgraph
indicates just that.
If you payed a closer attention to the structure of isgraph above, you will already know that this library function returns a non-zero value, given that a character has a visual display. In other case, 0 will be returned from this C function.
If you are familiar with other functions in the ctype.h
library - you may be wondering, how is, in fact, the isgraph
function any different from the isprint. And they only differ in a single case. When 32 (a space character) is passed as an argument to these functions, then isgraph
function, returns 0, indicating that a space is not a graphic character. The isprint
function, on the other hand, returns a non-zero value with the value of 32 as an input parameter.
Note: all the ASCII values between 33 and 126 ([33, 126]) can be visually displayed.
Example 1: usage of the isgraph function in C
#
include
<ctype.h>
#
include
<stdio.h>
int
main(
void
)
{
printf
(
"1. %d\n",
isgraph
(
'a'
));
printf
(
"2. %d",
isgraph
(
10
));
return
(
0
);
}
Possible output:
2. 0