gpt4 book ai didi

c - for 循环发出警告 : expression result unused [-Wunused-value]

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

我已经盯着它看了很久,但不明白为什么它会在 for 循环语句中给我一个警告。

//looks for a certain account by name in the provided list, return index 
//of account if found, else -1

int AccountSearch(BankArray bank, char name[100])
{
int i = 0;
for(i ; i < maxAccounts ; i++)
{
/* if this index contains the given value, return the index */
if (strcmp(bank->list[i]->accountName, name) == 0)
{
return i;
}
}

/* if we went through the entire list and didn't find the
* value, then return -1 signifying that the value wasn't found
*/
return -1;

}

最佳答案

for 循环中的第一个表达式未被使用,它等同于编写

i;

改成

for (; i < maxAccounts ; ++i)

或者更好,因为它只在第一次发现循环时执行,所以用它来初始化和声明i,像这样

for (int i = 0 ; i < maxAccounts ; ++i)

关于c - for 循环发出警告 : expression result unused [-Wunused-value],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34080191/

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