c语言字符串小写转大写程序
时间: 2023-06-22 20:23:52 浏览: 119
下面是一个 C 语言字符串小写转大写的示例程序:
```c
#include <stdio.h>
#include <ctype.h>
void to_upper(char *str) {
while (*str) {
*str = toupper(*str);
str++;
}
}
int main() {
char str[100];
printf("请输入一个字符串:");
fgets(str, sizeof(str), stdin);
to_upper(str);
printf("转换后的字符串为:%s", str);
return 0;
}
```
程序中使用了 `toupper()` 函数将字符串中的小写字母转成大写字母。函数 `to_upper()` 接受一个指向字符串的指针,然后遍历字符串中的每个字符,将小写字母转成大写字母。 `main()` 函数中获取用户输入的字符串,调用 `to_upper()` 函数将其转换成大写字母,并输出结果。
阅读全文