以下是用C语言编写的解决方案:

#include <stdio.h>

void toUpperCase(char *str) {
   int i = 0;
   while(str[i] != '\0') {
      if(str[i] >= 'a' && str[i] <= 'z') {
         str[i] = str[i] - 32;
      }
      i++;
   }
}

int main() {
   char str[100];
   printf("Enter a string:");
   scanf("%s", str);

   toUpperCase(str);

   printf("%s\n", str);

   return 0;
}

运行结果:

Enter a string: shanghai
SHANGHAI

原文地址: https://www.cveoy.top/t/topic/pkFF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录