检查字符串结尾是否有 NULL 字符,如果没有则添加一个。代码示例如下:
#include
#include
#include
int main() {
char str[] = "hello world";
int length = strlen(str);
// 检查字符串结尾是否有 NULL 字符
if (str[length-1] != '\0') {
str[length] = '\0';
}
// 将字符串转换为大写
for (int i=0; i
运行结果为:HELLO WORLD。