In C, the isalnum() function is used to check whether a character is alphanumeric or not. It is defined in the <ctype.h> header file and returns an integer value.
The possible return values of isalnum() are:
- If the character is alphanumeric (a letter or a digit), the function returns a nonzero value (true).
- If the character is not alphanumeric, the function returns zero (false).
Here’s an example usage of isalnum():
<span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string"><stdio.h></span></span>
<span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string"><ctype.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">isalnum</span>(ch)) {
<span class="hljs-built_in">printf</span>(<span class="hljs-string">"%c is alphanumeric.\n"</span>, ch);
} <span class="hljs-keyword">else</span> {
<span class="hljs-built_in">printf</span>(<span class="hljs-string">"%c is not alphanumeric.\n"</span>, ch);
}
<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}
In this example, the isalnum() function is used to check if the character 'A' is alphanumeric. Since it is a letter, the function returns a nonzero value, indicating that it is alphanumeric.
