w3resource

C isxdigit() function

C isxdigit(int ch)

The isxdigit() function is used to check whether a character is a hexadecimal digit character (0-9, a-f, A-F) or not. The function is defined in the ctype.h header file.

Syntax:

int isxdigit( int arg );

isxdigit() Parameters:

Name Description Required /Optional
ch Argument ch represents a uppercase letter. Required

Return value from isxdigit()

  • The isxdigit() returns non-zero if ch is a hexadecimal digit; otherwise returns 0.

Example-1: C isxdigit() function


#include <stdio.h>
#include <ctype.h>
int main() {
   char ch;
   int result;
   printf("Check whether a character is a hexadecimal digit character or not!\n");
   ch = 'a';
   result = isxdigit(ch);
   printf("\nReturn value is %d When %c is passed as an argemdent.", result, ch);
   ch = 'g';
   result = isxdigit(ch);
   printf("\nReturn value is %d When %c is passed as an argemdent.", result, ch);
   ch = 'i';
   result = isxdigit(ch);
   printf("\nReturn value is %d When %c is passed as an argemdent.", result, ch);
   ch = '0';
   result = isxdigit(ch);
   printf("\nReturn value is %d When %c is passed as an argemdent.", result, ch);
   return 0;
}

Output:

Check whether a character is a hexadecimal digit character or not!

Return value is 128 When a is passed as an argemdent.
Return value is 0 When g is passed as an argemdent.
Return value is 0 When i is passed as an argemdent.
Return value is 128 When 0 is passed as an argemdent.

Example-2: Program to Check Hexadecimal Character

#include <stdio.h>
#include <ctype.h>
int main() {
   char ch;
   printf("Input a character: ");
   ch = getchar();

   if (isxdigit(ch) != 0) 
   {
      printf("%c is a hexadecimal character.", ch);
   } 
   else 
   {
      printf("%c is not a hexadecimal character.", ch);
   }
   return 0;
}

Output:

Input a character: b
b is a hexadecimal character.

C Programming Code Editor:

Contribute your code and comments through Disqus.

Previous C Programming: C isupper()
Next C Programming: C tolower()



Share this Tutorial / Exercise on : Facebook and Twitter

C Programming: Tips of the Day

What's an object file in C?

An object file is the real output from the compilation phase. It's mostly machine code, but has info that allows a linker to see what symbols are in it as well as symbols it requires in order to work. (For reference, "symbols" are basically names of global objects, functions, etc.)

A linker takes all these object files and combines them to form one executable (assuming that it can, i.e.: that there aren't any duplicate or undefined symbols). A lot of compilers will do this for you (read: they run the linker on their own) if you don't tell them to "just compile" using command-line options. (-c is a common "just compile; don't link" option.)

Ref : https://bit.ly/3CbzF8M