C 语言中的 `isdigit` 函数用于检查给定字符是否为十六进制字符。下面的 `isdigit` 函数接受一个字符作为参数,并判断它是否为十六进制字符。
isxdigit(char)
C 语言 `isdigit` 编程示例
`isdigit` 函数用于判断用户输入的字符是否为十六进制字符。
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch = '5';
if(isxdigit(ch))
{
printf("\nYou have entered a Hexadecimal \n");
}
else
{
printf("\n %c is not a Hexadecimal", ch);
}
return 0;
}
You have entered a Hexadecimal
`isdigit` 示例 2
此程序允许用户输入任何字母。然后,它使用C 编程函数检查给定的字符是否为十六进制字符。
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
printf("Please Enter Any Valid Character: ");
scanf("%c", &ch);
if(isxdigit(ch))
{
printf("\nYou have entered a Hexadecimal Character \n");
}
else
{
printf("\n %c is not a Hexadecimal Character", ch);
printf("\n I request you to enter a Hexadecimal Character \n");
}
return 0;
}

让我输入另一个字符。
Please Enter Any Valid Character: #
# is not a Hexadecimal Character
I request you to enter a Hexadecimal Character