我遇到了这个问题,我只能使用 gcc -std=c99 进行编译,但是,我需要它使用 c89 又名 gcc -Wall 进行编译。这是我使用“for”循环的代码的一部分。请看看您是否可以帮助我,提前谢谢您。
#include<stdio.h>
int main()
{
int arr[100],i=0,ch;
int n = 1, sum = 0;
printf("Check out our selection! \n");
printf("Airhead - 25 cents\n");
printf("Fun Dip - 40 cents\n");
printf("Gummi Bears - 20 cents\n");
while (n != 0)
{
printf("Insert Coins: ");
scanf("%d",&n);
arr[i++] = n;
}
for(int j=0;j<i;j++)
{ sum = sum + arr[j];
}
......
最佳答案
这是错误的:
for (int j = 0; j < i; j++) {
sum = sum + arr[j];
}
您必须在函数开头初始化j
。
int main() {
int j;
...
for (j = 0; j < i; j++) {
sum = sum + arr[j];
}
}
关于c - 错误: 'for' loop initial declarations are only allowed in c99 mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44221148/