gpt4 book ai didi

c - 为什么 strcmp 在此上下文中不返回 0?

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

所以我从一个文件中一个一个地读取字符:

char temp[3];

temp[0] = nextchar;
printf("%c",temp[0]); //prints %

temp[1] = nextchar = fgetc(srcptr);
printf("%c",temp[1]); //prints 2

temp[2] = nextchar = fgetc(srcptr);
printf("%c",temp[2]); //prints 0

if(strcmp(temp, "%20") == 0) { printf("%s","blahblah"); }

理想情况下,这应该在末尾打印“blahblah”。然而,事实并非如此。那么为什么 strcmp 返回 0,更重要的是:我该如何修复它?

最佳答案

您需要使临时终止为空。

编辑

char temp[3]; 更改为 char temp[4];温度[3] = 0;

关于c - 为什么 strcmp 在此上下文中不返回 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10144375/

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