c语言中isxdigit函数,C语言 isxdigit()用法及代码示例

用C编程语言编写的isxdigit()函数检查给定字符是否为十六进制。 isxdigit()函数在ctype.h头文件中定义。

十进制数的十六进制等效项:

Hexadecimal:0 1 2 3 4 5 6 7 8 9 A B C D E F

Decimal: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

用法:

char isxdigit( char x);

Input:A

Output:Entered character is hexadecimal

Input:2

Output:Entered character is hexadecimal

Input:@

Output:Entered character is not hexadecimal

// C program to demonstrate isxdigit()

#include

#include

int main()

{

// taking input

char ch = 'A';

// checking is the given input is hexadecimal or not?

if (isxdigit(ch))

printf("\nEntered character is hexadecimal");

else

printf("\nEntered character is not hexadecimal");

}

输出:

Entered character is hexadecimal

应用:使用C编程语言编写的isxdigit()函数用于查找任何给定输入中存在的十六进制总数。

例:

Input:abc123

Output:Number of hexadecimals present in the given input is:6

Input:abcdef

Output:Number of hexadecimals present in the given input is:6

Input:123456@$

Output:Number of hexadecimals present in the given input is:6

让我们看一下有关此主题的C程序:

// C program to demonstrate isxdigit()

#include

#include

int ttl_hexadecimal(int i, int counter)

{

char ch;

char a[50] = "@#asf12345";

ch = a[0];

// counting of hexadecimal numbers

while (ch != '\0') {

ch = a[i];

if (isxdigit(ch))

counter++;

i++;

}

// returning total number of hexadecimal

// in the given input

return (counter);

}

int main()

{

int i = 0;

int counter = 0;

counter = ttl_hexadecimal(i, counter);

printf("\nNumber of hexadecimals in string"

" is:%d", counter);

return 0;

}

输出:

Number of hexadecimals in string is:7

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值