Your code is correct (in C99 and above). What for compilers are using your IDE's and on which OS?
I have compiled with GCC on Debian/GNU Linux. Here is the output:
Code:
$ gcc -Wall -o foo foo.c
foo.c: In function ‘main’:
foo.c:28:2: warning: zero-length gnu_printf format string [-Wformat-zero-length]
foo.c:29:2: warning: zero-length gnu_printf format string [-Wformat-zero-length]
foo.c:30:2: warning: zero-length gnu_printf format string [-Wformat-zero-length]
foo.c:32:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
foo.c:32:2: note: use option -std=c99 or -std=gnu99 to compile your code
The 3 warnings (line 28-30) are from printf-function with empty string.
The error came from declaration of variable 'i' inside the for-statment.
This is allowed since C99. I think you work on Windows.
I can compile the code without problems like …
Code:
gcc -std=c99 -Wall -o foo foo.c
gcc -std=c11 -Wall -o foo foo.c
… and it works as expected.