閱讀865 返回首頁    go 阿裏雲 go 技術社區[雲棲]


isdigit <ctype.h> <cctype>

原文:https://www.cplusplus.com/reference/clibrary/cctype/isdigit/

int isdigit ( int c );

檢查字符是否是十進製數字

檢查參數c是否是一個十進製數字。
十進製數字包括以下幾個數字: 0 1 2 3 4 5 6 7 8 9 
想要得到不同的ctype函數在處理每個標準ANSII字符返回值的詳細圖表,請閱讀參考<cctype>頭文件。
在C++語言中,一個特定於語言環境模版版本的isdigit函數存在於頭文件<locale>。

參數
c

 待檢查字符,被轉換成一個整數或者EOF結束符。


返回值

 如果事實上c是一個十進製數字,返回值為非0(例如:true)。否則,返回值為0 (例如:false)。

 
實例
/* isdigit example */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ()
{
  char str[]="1776ad";
  int year;
  if (isdigit(str[0]))
  {
    year = atoi (str);
    printf ("The year that followed %d was %d.\n",year,year+1);
  }
  return 0;
}

isdigit函數經常用來檢查str的第一個字符是否是數字,以便一個合法的字符數組能夠通過atoi函數轉換成一個整數。

最後更新:2017-04-02 06:52:06

  上一篇:go 係統架構-性能篇章2(係統拆分2-問題)
  下一篇:go islower &lt;ctype.h&gt; &lt;cctype&gt;