在 C 语言中,可以使用以下方法来将字符串 s 中的所有小写字母转换为大写字母:
#include <stdio.h>
#include <ctype.h>
int main() {
char s[] = "Hello, World!";
int i;
for (i = 0; s[i] != '\0'; i++) {
if (islower(s[i])) {
s[i] = toupper(s[i]);
}
}
printf("%s\n", s);
return 0;
}
在上面的代码中,我们使用了 islower
函数来检测字符是否为小写字母,并使用 toupper
函数将小写字母转换为大写字母。
输出:
HELLO, WORLD!