大小写转换
#include <stdio.h> #include <ctype.h> /* 大小写转换的库函数: int tolower(int c) int toupper(int c) */ int my_tolower(unsigned char c) { return (c + ('a' - 'A')); } int my_toupper(unsigned char c) { return (c - ('a' - 'A')); } int main(void) { printf("%c\n", my_tolower('G')); printf("%c\n", my_toupper('f')); printf("%c\n", tolower('G')); printf("%c\n", toupper('f')); return 0; }
输出:
g
F
g
F