用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 <ctype.h>
#include <stdio.h>
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 <ctype.h>
#include <stdio.h>
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
相關用法
- C語言 isalnum()用法及代碼示例
- C語言 isupper()用法及代碼示例
- C語言 fgets() and gets()用法及代碼示例
- C語言 Constants和Variables的區別用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 isxdigit() function in C Language。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。