以下程式接受使用者輸入字元,並且判斷是否為數字
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char t;
while (t = getchar()) {
if (t == EOF) {
break;
}
if (t == '\n') {
continue;
}
if (isdigit(t)) {
printf("對,是數字...\n");
}
else {
printf("不是數字喔...\n");
}
}
return 0;
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:cisdigit.c
功能:示範 ctype.h 中函數 isdigit() 的使用
作者:張凱慶
時間:西元2010年6月 */編譯後執行,結果如下

您可以繼續參考
沒有留言:
張貼留言