#include <stdio.h> #include <ctype.h> // tolower() 返回小写 toupper() 返回大写 函数原型库 #include <stdbool.h> int main() { char ch; int i; bool j; printf("字母大小写转换程序\n"); printf("请选择转换模式, 0 输出为小写, 1 输出为大写: "); scanf_s("%d", &i); j = (i > 0) ? false : true; /* if (i > 0) j = false; else j = true; */ getchar(); printf("请输入字母: "); ch = getchar(); while (ch != '\n') { if (j) { if (ch = tolower(ch)) putchar(ch); else putchar(ch); } else { if (ch = toupper(ch)) putchar(ch); else putchar(ch); } ch = getchar(); } putchar(ch); system("pause"); return 0; }