小写字母转化为大写字母C语言
时间: 2023-10-14 22:26:37 浏览: 113
可以使用C语言中的内置函数toupper()将小写字母转化为大写字母。
例如,下面的代码将字符串中的小写字母转化为大写字母:
```c
#include <stdio.h>
#include <ctype.h>
int main() {
char str[] = "Hello, World!";
int i;
for (i = 0; str[i]; i++) {
str[i] = toupper(str[i]);
}
printf("%s", str);
return 0;
}
```
输出结果为:
```
HELLO, WORLD!
```
相关问题
c语言中小写字母转化为大写字母
在C语言中,可以使用标准库函数toupper()将小写字母转换为大写字母。toupper()函数的原型定义在头文件<ctype.h>中,其函数声明如下:
int toupper(int c);
其中,参数c是要转换的字符,返回值是转换后的字符。需要注意的是,toupper()函数只能处理单个字符,如果需要将一个字符串中的所有小写字母转换为大写字母,需要使用循环结构遍历字符串中的每个字符并调用toupper()函数进行转换。
以下是一个简单的示例代码:
```
#include <stdio.h>
#include <ctype.h>
int main()
{
char str[] = "hello world";
int i;
for(i = 0; str[i] != '\0'; i++)
{
str[i] = toupper(str[i]);
}
printf("转换后的字符串为:%s\n", str);
return 0;
}
--相关问题--:
C语言将小写字母转换为大写字母
可以使用 C 语言中的 toupper 函数将小写字母转换为大写字母。例如,下面的代码可以将字符串 str 中的所有小写字母转换为大写字母:
```
#include <stdio.h>
#include <ctype.h>
int main() {
char str[] = "Hello, World!";
int i;
for (i = 0; str[i]; i++) {
str[i] = toupper(str[i]);
}
printf("%s\n", str);
return 0;
}
```
输出结果为:
```
HELLO, WORLD!
```