C library functions -isxdigit()

C Standard Library - <ctype.h>

Description

C Library Functionsint isxdigit(int c)Check whether the passed character is a hexadecimal digit.

int isxdigit(int c)Parameter c is a single character.

Hexadecimal is generally represented by the digits 0 to 9 and the letters A to F (or a~f), where A~F represent 10~15:0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F。

Declaration

Below is the declaration of the isxdigit() function.

int isxdigit(int c);

Parameter

  • c-- This is the character to be checked.

Return Value

If c is a hexadecimal digit, the function returns a non-zero integer value; otherwise it returns 0.

Example

The following example demonstrates the usage of the isxdigit() function.

Example

#include <ctype.h> #include <stdio.h> int main() { char c = '5'; int result; // pass in a character result = isxdigit(c); // result returns non-zero printf("%c passed to isxdigit() function result is: %d", c, isxdigit(c)); printf("\n"); // newline c = 'M'; // non-hexadecimal number as parameter result = isxdigit(c); // result is 0 printf("%c passed to isxdigit() function result is: %d", c, isxdigit(c)); return 0; }

Let us compile and run the above program, this will produce the following result:

5 传入到 isxdigit() 函数结果为: 1
M 传入到 isxdigit() 函数结果为: 0

Find the characters in the string that are hexadecimal digits:

Example

#include<ctype.h> #include<stdio.h> int main() { char str[]="123c@#run[oobe?"; int i; for(i=0;str[i]!='\0';i++) { if(isxdigit(str[i])) { printf("%c is a hexadecimal number\n",str[i]); } } }

Let us compile and run the above program, this will produce the following result:

1 是一个十六进制数
2 是一个十六进制数
3 是一个十六进制数
c 是一个十六进制数
b 是一个十六进制数
e 是一个十六进制数

C Standard Library - <ctype.h>

other extensions