C <ctype.h> - isxdigit() Function
The C <ctype.h> isxdigit() function is used to check if the given character is a hexadecimal digit or not. Hexadecimal digits are one of the following character: 0123456789abcdefABCDEF.
Syntax
int isxdigit ( int ch );
Parameters
ch |
Specify the character to be checked, casted to an int, or EOF. |
Return Value
Returns non-zero value (i.e, true) if ch is a hexadecimal digit, else returns zero (i.e, false).
Example:
The example below shows the usage of isxdigit() function.
#include <stdio.h> #include <ctype.h> int main (){ char str[] = "ff123YZ"; //counting the numbers of //hexadecimal digits in str int i = 0, count = 0; while(str[i]) { if(isxdigit(str[i])) count++; i++; } //displaying the output printf("%s contains %d hexadecimal digits.", str, count); return 0; }
The output of the above code will be:
ff123YZ contains 5 hexadecimal digits.
❮ C <ctype.h> Library