Can someone elaborate on the following gcc error?
$ gcc -o Ctutorial/temptable.out temptable.c
temptable.c: In function ‘main’:
temptable.c:5: error: ‘for’ loop initial declaration used outside C99 mode
temptable.c:
...
/* print Fahrenheit-Celsius Table */
main()
{
for(int i = 0; i <= 300; i += 20)
{
printf("F=%d C=%d\n",i, (i-32) / 9);
}
}
P.S: I vaguely recall that int i
should be declared before a for
loop. I should state that I am looking for an answer that gives a historical context of C standard.
(5 * (i - 32)) / 9
(the5
is missing). Usually, you need floating point arithmetic – but then you need to change your printf format fromC=%d
toC=%./2f
or something similar too (and you convert with(5.0 * (i - 32)) / 9.0
).