6.3.12 isxdigit Function
Test for a hexadecimal digit.
Include
<ctype.h>
Prototype
int isxdigit (int c);
Argument
c
- The character to test.
Return Value
Returns a non-zero integer value if the character, c
, is a
hexadecimal digit; otherwise, returns zero.
Remarks
A character is considered to be a hexadecimal digit character if it is in the range of
'0'
-'9'
,
'A'
-'F'
, or 'a'
-'f'
.
Note: The list does not include the x
character, which is used
when writing a hexadecimal value, such as 0x7FFE
. This function
looks purely to see if the character is a hexadecimal digit.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <ctype.h>
#include <stdio.h>
int main(void)
{
int ch;
ch = 'B';
if (isxdigit(ch))
printf("B is a hexadecimal digit\n");
else
printf("B is NOT a hexadecimal digit\n");
ch = 't';
if (isxdigit(ch))
printf("t is a hexadecimal digit\n");
else
printf("t is NOT a hexadecimal digit\n");
}
Example Output
B is a hexadecimal digit
t is NOT a hexadecimal digit