The isxdigit function in C checks whether a character is a hexadecimal digit. Hexadecimal digits include the numbers , uppercase letters , and lowercase letters .
To use the isxdigit function, you will need to include the <ctype.h> library in the program, as shown below:
#include <ctype.h>
The prototype of the isxdigit function is shown below:
int isxdigit(int c);
The isxdigit function takes a single mandatory parameter, i.e., an integer that represents the character you want to check.
Note: In the C language, characters are treated as integer values.
If the argument passed to the isxdigit function is a valid hexadecimal character, then the function returns a non-zero integer; otherwise, it returns .
The code below shows how the isxdigit function works in C:
#include <stdio.h>#include <ctype.h>#include <string.h>int main() {// initializing stringchar str[] = "ae2k3F9J";// extracting charactersfor(int i = 0; i < strlen(str); i++){// hexadecimal checkif(isxdigit(str[i])){printf("\'%c\' is a hexadecimal digit.\n", str[i]);}else{printf("\'%c\' is not a hexadecimal digit.\n", str[i]);}}return 0;}
First, the code initializes a character array. A for-loop iterates over the length of this array and extracts each character.
Each extracted character is then provided as an argument to the isxdigit function on line 15.
The isxdigit function proceeds to check if the character is a valid hexadecimal digit and outputs the result accordingly.
Free Resources