gpt4 book ai didi

c - "statemenet with no effect" eclipse 错误

转载 作者:太空宇宙 更新时间:2023-11-04 01:10:09 25 4
gpt4 key购买 nike

我有这行代码,

newCust.idNumber == ID;

ID 的值是字符串类型并且已经分配,​​newCust 是我的结构的名称,idNumber 是我的结构中的一个字符串,我想将 ID 的值分配给结构的 ID 号,知道为什么这行代码是一个“无效的声明”。我正在使用eclipse,我是C编程的初学者

最佳答案

这是因为 == 比较两个值,并丢弃比较结果。虽然像这样的表达式语句在 C 中是完全合法的,但它们非常不常见,并且经常作为您输入错误内容的指示器。这就是编译器警告您的原因。

编辑:

I tried the = also, and i get this error then, incompatible types when assigning to type char[60] from type char *

你不能像那样分配字符串:你需要使用 strcpy,像这样:

strcpy(newCust.idNumber, ID);

确保 newCust.idNumber 足够长以适应 ID 及其空终止符,即假设 newCust.idNumberchar[60]ID的值必须小于等于59个字符。

关于c - "statemenet with no effect" eclipse 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14218647/

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