基本介紹
- 外文名:isdigit
- 頭檔案:<ctype.h>(C)<cctype>(C++)
- 函式定義:int isdigit(int c)
- 函式說明:檢查參數是否為十進制數字字元
返回值,函式實現,範例,
返回值
若參數c為阿拉伯數字0~9,則返回非0值,否則返回0。
函式實現
isdigit底層通過宏定義實現。
範例
(C)
/* 找出字元數組str中為阿拉伯數字0~9的字元*/#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;}
(C++)
/* 找出字元串str中為阿拉伯數字0~9的字元*/#include<iostream>#include<cctype>using namespace std;int main(){ string str = "123@#FDsP[e?"; for(int i = 0; str[i] != 0; ++i) { if(isdigit(str[i])) cout << str[i] << " is an digit character\n" <<endl; } return 0;}