C Library - isxdigit() function



The C library isupper() function checks whether the passed character is a hexadecimal digit. Hexadecimal digits include the characters '0'-'9', 'a'-'f', and 'A'-'F'.

This function is a part of the C standard library, defined in the header file <ctype.h>

Syntax

Following is the C library syntax of the isupper() function −

int isxdigit(int c);

Parameters

This function accepts a single parameter −

  • c − This is the character to be checked, passed as an integer. The character is typically an unsigned char value or EOF.

Return Value

The isxdigit function returns a non-zero value (true) if the character is a hexadecimal digit. Otherwise, it returns zero (false).

Example 1: Checking a Hexadecimal Digit

In this example, 'A' is a valid hexadecimal digit, so isxdigit(c) returns true.

#include <stdio.h>
#include <ctype.h>

int main() {
   char c = 'A';

   if (isxdigit(c)) {
      printf("'%c' is a hexadecimal digit.\n", c);
   } else {
      printf("'%c' is not a hexadecimal digit.\n", c);
   }
   return 0;
}

Output

The above code produces following result−

'A' is a hexadecimal digit.

Example 2: Checking a Numeric Character c

Here, the isxdigit() function takes the numeric charachter and checks if it is hexadeciam or not.

#include <stdio.h>
#include <ctype.h>

int main() {
   char c = '5';

   if (isxdigit(c)) {
      printf("'%c' is a hexadecimal digit.\n", c);
   } else {
      printf("'%c' is not a hexadecimal digit.\n", c);
   }
   return 0;
}

Output

After execution of above code, we get the following result

'5' is a hexadecimal digit.
Advertisements