int main(void) { if(isdigit('11') == 1){ printf("数字"); } else{ printf("数字ではない"); } return 0; } int isdigit(char ch) { if(ch >= '0' && ch <= '9'){ return 1; } else{ return 0; } }このプログラムでcharがintになってるのですがこのプログラムはおかしいでしょうか?
軽くテストしてみましたが求める結果にはなります。
#include <assert.h> #include <limits.h> #include <stdio.h> int isdigit(int c) { assert(0 <= c && c <= UCHAR_MAX || c == EOF); if ('0' <= c && c <= '9' && c != EOF) return 1; return 0; }ということになります。