C語言ascII與數字轉化的問題,值得新手看看
阿新 • • 發佈:2018-12-13
從鍵盤輸入一個字元,若該字元是小寫字母,輸出“該字元 is a lower case letter.”,若該字元是大寫字母,輸出“該字元 is a capital letter.”,若既不是小寫字母也不是大寫字母,則輸出“該字元 is the other one.”。
輸入一個字元輸出該字元的型別樣例輸入?樣例輸出? is the other one. 請問這個怎麼寫?
C語言的字元型別char預設就是儲存的ASCII不用轉換的
另外,C語言本身提供一套判斷字元的函式的(不用自己寫的)
程式很簡單的
#include<stdio.h> #include<ctype.h> int main() { char c; c=getchar(); if (islower(c)) printf("該字元 is a lower case letter.\n"); else if (isupper(c)) printf("該字元 is a capital letter.\n"); else printf("該字元 is the other one.\n"); return 0; }
若要自己寫判斷也簡單的,如
if(islower(c))
可用
if(c>='a' && c<='z')