C 庫 - isxdigit() 函式



C 庫函式 isupper() 檢查傳遞的字元是否為十六進位制數字。十六進位制數字包括字元 '0'-'9'、'a'-'f' 和 'A'-'F'。

此函式是 C 標準庫的一部分,在標頭檔案 <ctype.h> 中定義。

語法

以下是 C 庫函式 isupper() 的語法:

int isxdigit(int c);

引數

此函式接受一個引數:

  • c − 這是要檢查的字元,作為整數傳遞。字元通常是無符號 char 值或 EOF。

返回值

如果字元是十六進位制數字,則 isxdigit 函式返回非零值 (true);否則返回零 (false)。

示例 1:檢查十六進位制數字

在此示例中,'A' 是有效的十六進位制數字,因此 isxdigit(c) 返回 true。

#include <stdio.h>
#include <ctype.h>

int main() {
   char c = 'A';

   if (isxdigit(c)) {
      printf("'%c' is a hexadecimal digit.\n", c);
   } else {
      printf("'%c' is not a hexadecimal digit.\n", c);
   }
   return 0;
}

輸出

以上程式碼產生以下結果:

'A' is a hexadecimal digit.

示例 2:檢查數字字元 c

在這裡,isxdigit() 函式接收數字字元並檢查它是否是十六進位制。

#include <stdio.h>
#include <ctype.h>

int main() {
   char c = '5';

   if (isxdigit(c)) {
      printf("'%c' is a hexadecimal digit.\n", c);
   } else {
      printf("'%c' is not a hexadecimal digit.\n", c);
   }
   return 0;
}

輸出

執行以上程式碼後,我們得到以下結果:

'5' is a hexadecimal digit.
廣告