//uplow.c --- @CopyLeft by tsaiwn@csie.nctu.edu.tw //程式庫中的 isupper(int) 遇到大寫字母不一定回傳 1 //因為它可能把它分類, 回傳的是類別代號; 反正不是 0 就代表 true // 此例用 Dev-Cpp (MinW32 gcc/g++), isupper 是回傳 1 // 但請注意此例中, 程式庫的 islower 是回傳 0 或 2; 不會是 1 //// 我們自己寫的 myLower 則是回傳 0 或 1; 這是 OK 的! #include #include int myUp(int x) { return x >= 'A' && x <= 'Z'; // 'A'..'Z' 才回答 yes } int myLower(int x) { return x >= 'a' && x <= 'z'; // 'a'..'z' 才回答 yes } int main( ) { printf("isupper(65)==%d, isupper(97)==%d\n", isupper(65), isupper(97) ); //65=='A', 97=='a' if(myUp('a'))printf(" YES a is UPPER; "); else printf(" no. a is NOT UPPER case\n"); printf(" myUp('a')=%d\n", myUp('a') ); /// if(myUp('A'))printf(" YES A is UPPER; "); else printf(" no. A is NOT UPPER case\n"); printf(" myUp('A')=%d\n", myUp('A') ); /// /// printf("islower('A')==%d, islower('a')==%d\n", islower('A'), islower('a') ); //65=='A', 97=='a' if(myLower('a'))printf(" YES a is lower; "); else printf(" no. a is NOT in lower case\n"); printf(" myLower('a')=%d\n", myLower('a') ); /// if(myLower('A'))printf(" Yes. A is lower; "); else printf(" no. A is NOT in lower case\n"); printf(" myUp('A')=%d\n", myUp('A') ); /// printf(" ... Hit ENTER key ..."); getchar( ); return 0; } /****** D:\testc> path c:\Dev-Cpp\bin;%path% D:\testc> gcc uplow.c D:\testc> a isupper(65)==1, isupper(97)==0 no. a is NOT UPPER case myUp('a')=0 YES A is UPPER; myUp('A')=1 islower('A')==0, islower('a')==2 YES a is lower; myLower('a')=1 no. A is NOT in lower case myUp('A')=1 ... Hit ENTER key ... =======================************/