在C語言中利用封裝好的函式實現英文字母的大小寫轉換
阿新 • • 發佈:2019-02-10
在C語言中,利用tolower和toupper兩個函式實現英文字母的大小寫之間的轉換
範例1:將s字串內的小寫字母轉換成大寫字母
#include <ctype.h> int main() { char s[] = "aBcDeFgH"; int i; printf("before toupper() : %s\n", s); for(i = 0; i < sizeof(s); i++) s[i] = toupper(s[i]); printf("after toupper() : %s\n", s); return 0; }
範例2:將s字串內的大寫字母轉換成小寫字母
#include <ctype.h>
int main()
{
char s[] = "aBcDeFgH";
int i;
printf("before tolower() : %s\n", s);
for(i = 0; i < sizeof(s); i++)
s[i] = tolower(s[i]);
printf("after tolower() : %s\n", s);
return 0;
}