-
isdigit
鎖定
isdigit是計算機C(C++)語言中的一個函數,主要用於檢查其參數是否為十進制數字字符。
[1]
- 外文名
- isdigit
- 頭文件
- (C)(C++)
- 函數定義
- int isdigit(int c)
- 函數説明
- 檢查參數是否為十進制數字字符
isdigit返回值
若參數c為阿拉伯數字0~9,則返回非0值,否則返回0。
isdigit函數實現
isdigit底層可以通過宏定義或函數實現。
isdigit範例
/* 找出字符數組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" <<endl; } return 0; }
- 參考資料
-
- 1. isdigit .cplusplus[引用日期2017-07-17]