I've been staring at this for ages and can't figure out why it's giving me a warning at the for-loop statement.
我多年来一直盯着这个,无法弄清楚为什么它会在for-loop语句中给我一个警告。
//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;
}
1 个解决方案
#1
2
The first expression in your for
loop is not used and it's equivalent to writing
你的for循环中的第一个表达式没有被使用,它等同于写作
i;
change it to
改为
for (; i < maxAccounts ; ++i)
or better, since it's only executed the very first time the loop is found, use it to initialize and declare i
, like this
或者更好,因为它只在第一次找到循环时执行,用它来初始化并声明我,就像这样
for (int i = 0 ; i < maxAccounts ; ++i)
#1
2
The first expression in your for
loop is not used and it's equivalent to writing
你的for循环中的第一个表达式没有被使用,它等同于写作
i;
change it to
改为
for (; i < maxAccounts ; ++i)
or better, since it's only executed the very first time the loop is found, use it to initialize and declare i
, like this
或者更好,因为它只在第一次找到循环时执行,用它来初始化并声明我,就像这样
for (int i = 0 ; i < maxAccounts ; ++i)