用C语言将一串字符串全部换为小写字母
时间: 2023-12-03 10:43:35 浏览: 45
可以使用C语言中的标准库函数`tolower()`将字符串中的每个字符转换为小写字母。以下是一个示例代码:
```c
#include <stdio.h>
#include <ctype.h>
int main() {
char str[] = "HELLO WORLD";
int i = 0;
while (str[i]) {
str[i] = tolower(str[i]);
i++;
}
printf("Lowercase string: %s\n", str);
return 0;
}
```
输出结果为:
```
Lowercase string: hello world
```
在上面的代码中,我们使用`tolower()`函数将字符串中的每个字符都转换为小写字母。在`while`循环中,我们逐个字符地访问字符串中的每个元素,并使用`tolower()`函数将其转换为小写字母。最后,我们打印出转换后的字符串。
相关问题
c语言将字符串中的大写字母转换为对应的小写字母
可以使用C语言中的标准库函数`tolower()`将字符串中的大写字母转换为小写字母。下面是一个示例代码:
```c
#include <stdio.h>
#include <ctype.h>
int main() {
char str[] = "HELLO WORLD";
int i;
for(i = 0; str[i]; i++){
str[i] = tolower(str[i]);
}
printf("转换后的字符串为: %s", str);
return 0;
}
```
输出结果为:
```
转换后的字符串为: hello world
```
在上面的代码中,我们使用了`tolower()`函数将字符串中的大写字母转换为小写字母。在循环中,我们遍历字符串中的每个字符,并调用`tolower()`函数将其转换为小写字母。最后打印出转换后的字符串。
用c语言将一个字符串中的大写字母转换成小写字母输出
可以使用C语言中的标准库函数`tolower()`来实现将大写字母转换成小写字母的操作。
下面是一个示例代码:
```c
#include <stdio.h>
#include <ctype.h>
int main() {
char str[] = "Hello, WORLD!";
int i;
printf("Original string: %s\n", str);
for(i = 0; str[i]; i++) {
str[i] = tolower(str[i]);
}
printf("Lowercase string: %s\n", str);
return 0;
}
```
输出结果:
```
Original string: Hello, WORLD!
Lowercase string: hello, world!
```
在上面的代码中,我们首先定义一个字符串`str`,然后使用`tolower()`函数将其中的大写字母转换成小写字母,并将结果存储回原字符串中,最后输出转换后的字符串。