C语言代码实现字符串小写字母转大写
#include <stdio.h>
void convert_lowercase_to_uppercase(char* input_string) { int i = 0; while (input_string[i] != '\0') { if (input_string[i] >= 'a' && input_string[i] <= 'z') { input_string[i] = input_string[i] - 32; } i++; } }
int main() { char user_input[100]; printf("请输入一个字符串:"); fgets(user_input, sizeof(user_input), stdin);
convert_lowercase_to_uppercase(user_input);
printf("转换后的字符串为:%s", user_input);
return 0;
}
这段代码定义了一个名为 convert_lowercase_to_uppercase 的函数,它接受一个字符指针作为输入,并将其中的小写字母转换为大写字母。在 main 函数中,我们首先声明了一个字符数组 user_input 来存储用户输入的字符串。然后,通过调用 convert_lowercase_to_uppercase 函数对用户输入的字符串进行转换。最后,将转换后的结果打印出来。
请注意,这是一个基于 C 语言的示例代码,与 GPT-3.5 Turbo 模型无关。
原文地址: https://www.cveoy.top/t/topic/TkJ 著作权归作者所有。请勿转载和采集!