在C语言中,将大写字母转换为小写字母可以通过以下几种方法实现:
使用库函数 `tolower`
```c
include include int main() { char ch; scanf("%c", &ch); printf("%c", tolower(ch)); return 0; } ``` ```c include int main() { char ch; scanf("%c", &ch); if (ch >= 'A' && ch <= 'Z') { ch += 32; } printf("%c", ch); return 0; } ``` ```c include void convertCase(char *str) { int i = 0; while (str[i] != '\0') { if (str[i] >= 'A' && str[i] <= 'Z') { str[i] = str[i] + 32; } i++; } } int main() { char str; printf("请输入一个字符串: "); scanf("%s", str); convertCase(str); printf("转换后的字符串为: %s\n", str); return 0; } ``` ```c include include int main() { char ch; while ((ch = getchar()) != EOF) { putchar(tolower(ch)); } return 0; } ``` ```c include void upper(char string) { while (string) { if (string >= 'a' && string <= 'z') { string = string - 32; } } } int main() { char string; printf("enter a string to convert to lower case: "); gets(string); upper(string); printf("The string in lower case: %s\n", string); return 0; } ``` 这些方法都可以实现将大写字母转换为小写字母的功能。选择哪种方法取决于具体的需求和编程风格。通过ASCII码值进行转换
使用字符数组和ASCII码进行转换
使用预定义函数 `toupper` 和 `tolower`
使用位运算进行转换