目前正在尝试修复一段时间未使用的代码。
我有两个变量:int8_t foo[size]
和const char* const bar
.
有一个 if 检查if(0 != strcmp((char *)foo, bar))
目前,即使printf("%s | %s", foo, bar)
返回两个完全相同的字符串,这也是失败的。我也试过strncmp
了,也失败了。
通过在线研究,我知道这很可能是由于终止了空字节,但是我不知道如何解决/解决这个问题。
int8_t foo[size];
const char* const bar;
if(0 != strcmp((char *)foo, bar)){
fail
}
预期结果strcmp
返回 0,因为打印时两个字符串相同。
实际结果:返回失败。
实际数据:5352A565712345657567565785658956581
运行时printf("Value of foo and bar: %s and %s", foo, bar)
,两个变量都返回上面的数据。