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()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/c-programming/ctype/c-isxdigit.php