大小寫轉換原理:根據ascii值來對字符進行大小寫轉換。每個字符在計算機存儲中都是轉換成ascii碼值。然後再轉換爲0和1;
函數方法:
//小寫轉大寫
int toupper(int c) {
if(c >= 'a' && c <= 'z')
return c + 'A' - 'a';
return c;
}
int tolower (int c) {
if(c >= 'A' && c <= 'Z')
return c + 'a' - 'A';
return c;
}
宏方法:
#define _toupper(c) ((c) + 'A' - 'a')
#define _tolower(c) ((c) + 'a' - 'A')