In the C programming language, the isgraph() function is part of the <ctype.h> library and is used to determine whether a character is a printable character other than a space. It checks if the character passed as an argument is a graphical character, which means it has a visible representation when printed.
The isgraph() function takes an integer representing a character as its argument and returns an integer value. It returns a non-zero value if the character is a graphical character, and zero otherwise.
The purpose of isgraph() is to perform character classification and enable programmers to check if a character is printable and not a space. It is useful in situations where you need to process characters and filter out any non-printable or non-graphical characters. It is commonly used in text processing and input validation scenarios to ensure that the input contains only visible and meaningful characters.
Here’s an example that demonstrates the usage of isgraph():
<span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string"><ctype.h></span></span>
<span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string"><stdio.h></span></span>
<span class="hljs-type">int</span> <span class="hljs-title function_">main</span><span class="hljs-params">()</span> {
<span class="hljs-type">char</span> ch = <span class="hljs-string">'A'</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-built_in">isgraph</span>(ch)) {
<span class="hljs-built_in">printf</span>(<span class="hljs-string">"%c is a graphical character.\n"</span>, ch);
} <span class="hljs-keyword">else</span> {
<span class="hljs-built_in">printf</span>(<span class="hljs-string">"%c is not a graphical character.\n"</span>, ch);
}
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}
In this example, the program checks if the character 'A' is a graphical character using isgraph(). If it is, it prints that it is a graphical character; otherwise, it prints that it is not a graphical character.
