gpt4 book ai didi

c - C 中的 if 语句主体未执行

转载 作者:行者123 更新时间:2023-11-30 21:41:42 26 4
gpt4 key购买 nike

为什么当我运行程序时,if 语句中的 tolower(*(text+i)); 没有被执行?

#include <stdio.h>
#include <ctype.h>


void vowel_caser(char text[])
{
int i = 0;
while(*(text+i) != '\0')
{
if (*(text+i) == 'A' || *(text+i) == 'E' || *(text+i) == 'I' || *(text+i) == 'O' || *(text+i) == 'U')
{
tolower(*(text+i));
}
i++;
}
}


int main()
{
char test[] = "This is An example";
vowel_caser(test);
puts(test);
return 0;
}

最佳答案

tolower 返回新值。
它不会就地修改值。

如果你想修改角色,你需要:

 text[i] = tolower(text[i]);

关于c - C 中的 if 语句主体未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59763006/

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