/***************************************************************** アスキーコードの表示とアルファベット大文字、小文字の判定 ex01/prog02b.c Last update: Sep 10 2026 *****************************************************************/ #include /* マクロ定義 */ #define TRUE 1 #define FALSE 0 /* プロトタイプ宣言 */ int isAlphabetic(char); int isUppercase(char); int main() { char c; printf("Enter any characters: "); while (scanf("%c", &c) && c != '\n'){ printf("'%c': %3d (Decimal) / 0x%02x (Hexadecimal). ", c, c, c); if (isAlphabetic(c) == TRUE){ if (isUppercase(c) == TRUE){ printf("It's an upper-case character.\n"); } else { printf("It's a lower-case character.\n"); } } else { printf("It's a non-alphabetic character.\n"); } /* 条件判断で、== TRUE は無くても動作は同じだが、わざわざマクロ TRUEとFALSEを定義していることをふまえて、上記のように書いた */ } return 0; } /***************************************** アルファベット文字判別関数 アルファベット文字:TRUE, それ以外:FALSE *****************************************/ int isAlphabetic(char c) { if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) return TRUE; return FALSE; } /***************************************** アルファベット大文字判別関数 アルファベット大文字:TRUE, それ以外:FALSE *****************************************/ int isUppercase(char c) { if (c >= 'A' && c <= 'Z') return TRUE; return FALSE; }