Solution:
This occurs since declaring variables within a for loop wasn't valid C until C99(which is the standard of C published in 1999), you can either declare your counter outside the for as pointed out by others or employ the -std=c99 flag to inform the compiler apparently that you're employing this standard and it must interpret it as such.
You require to declare the variable j employed for the first for loop before the loop.
int j;
for(j=0;j<5;j++)
printf("%d",Arr[j]);
I'd attempt to declare i
outside of the loop!
#include <stdio.h>
int main() {
int i;
/* for loop execution */
for (i = 10; i < 20; i++) {
printf("i: %d\n", i);
}
return 0;
}
There is a compiler switch which enables C99 mode, which amongst other things approves declaration of a variable within the for loop. To turn it on employ the compiler switch -std=c99
To switch to C99 mode in CodeBlocks, pursue the next steps:
Click Project/Build options, then in tab Compiler Settings choose subtab Other options, and place -std=c99
in the text area, and click Ok.
This will turn C99 mode on for your Compiler.
I've gotten this error too.
for (int i=0;i<10;i++) { ..
is not valid in the C89/C90 standard. As OysterD says, you require to do:
int i;
for (i=0;i<10;i++) { ..
in case you compile in C change
for (int i=0;i<10;i++) { ..
To
int i;
for (i=0;i<10;i++) { ..
You can further compile with the C99 switch set. Put -std=c99 in the compilation line:
gcc -std=c99 foo.c -o foo