C語言ctype頭文件(ctype.h)中isxdigit函數的用法及代碼示例。
用法:
int isxdigit ( int c );
檢查字符是否為十六進製數字
十六進製數字為:0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
有關不同之處的詳細圖表ctype函數針對標準ANSII字符集的每個字符返回,請參見<cctype>標頭。
在C++中,此函數的locale-specific模板版本(isxdigit)存在於標題中<locale>。
參數
- c
- 要檢查的字符,強製轉換為int, 或者EOF。
返回值
不同於零的值(即,true)如果確實c是一個十六進製數字。零(即false) 否則。示例
/* isxdigit example */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ()
{
char str[]="ffff";
long int number;
if (isxdigit(str[0]))
{
number = strtol (str,NULL,16);
printf ("The hexadecimal number %lx is %ld.\n",number,number);
}
return 0;
}
isxdigit用於檢查第一個字符是否str是有效的十六進製數字,因此是要轉換的有效候選strtol成為一個整數值。輸出:
The hexadecimal number ffff is 65535. |
相關用法
- C語言 isalnum用法及代碼示例
- C語言 isalpha用法及代碼示例
- C語言 isblank用法及代碼示例
- C語言 iscntrl用法及代碼示例
- C語言 isdigit用法及代碼示例
- C語言 isgraph用法及代碼示例
- C語言 islower用法及代碼示例
- C語言 isprint用法及代碼示例
- C語言 ispunct用法及代碼示例
- C語言 isspace用法及代碼示例
- C語言 isupper用法及代碼示例
- C語言 tolower用法及代碼示例
- C語言 toupper用法及代碼示例
注:本文由純淨天空篩選整理自C標準庫大神的英文原創作品 C isxdigit function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。