大小写字母转换(手机大小写字母转换)

大小写字母转换(手机大小写字母转换)

编码文章call10242025-07-11 21:49:264A+A-

c语言

#include <stdio.h>

#include <string.h>


int main() {

char str[100];

printf("请输入一串英文字母:");

// 读取字符串,遇到换行、空格等结束(若需处理带空格的,可用 fgets)

scanf("%s", str);

int len = strlen(str);

for (int i = 0; i < len; i++) {

if (str[i] >= 'a' && str[i] <= 'z') {

// 利用 ASCII 码差值,小写转大写

str[i] = str[i] - 'a' + 'A';

}

}

printf("转换后的字符串:%s\n", str);

return 0;

}

点击这里复制本文地址 以上内容由文彬编程网整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

文彬编程网 © All Rights Reserved.  蜀ICP备2024111239号-4