In C, the ispunct() function is a standard library function declared in the <ctype.h> header. It is used to determine whether a given character is a punctuation character or not.
The ispunct() function takes an integer representing a character as an argument and returns an integer value. It returns a non-zero value if the character is a punctuation character and 0 if it is not. The character is typically passed as an int or unsigned char type, or EOF (End-of-File) value for input/output functions.
Here’s the function signature of ispunct():
<span class="hljs-type">int</span> <span class="hljs-title function_">ispunct</span><span class="hljs-params">(<span class="hljs-type">int</span> c)</span>;
The c parameter represents the character to be tested. It can be any valid character represented as an integer.
Here’s an example usage of ispunct():
<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">'@'</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-built_in">ispunct</span>(ch)) {
<span class="hljs-built_in">printf</span>(<span class="hljs-string">"%c is a punctuation 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 punctuation character.\n"</span>, ch);
}
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}
In the above example, the ispunct() function is used to check whether the character ch is a punctuation character. If it is, a message stating so is printed; otherwise, a different message is printed.
