gpt4 book ai didi

c - 空终止错误在哪里?

转载 作者:行者123 更新时间:2023-12-02 08:19:24 26 4
gpt4 key购买 nike

<分区>

我正在复习这个练习(完整的源代码): http://c.learncodethehardway.org/book/ex29.html

部分代码如下所示:

int uppercase(const char *msg)
{
int i = 0;

// BUG: \0 termination problems
for(i = 0; msg[i] != '\0'; i++) {
printf("%c", toupper(msg[i]));
}

printf("\n");

return 0;
}

作者评论说有一个错误。后来他的指示说:

Were you paying attention to the bad code I have in the libex29.c functions? See how, even though I use a for-loop they still check for '\0' endings? Fix this so the functions always take a length for the string to work with inside the function.

但是,我没有看到这里的错误。因为如果有空字符,循环将终止。

还有其他人在这里看到问题吗?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com