>>all the variables must be declared at the top of that function
No, as said by Salem, local variables must be declared at the top of the code block, not the function.
So, a very simplistic example would be this:
Code:
#include <stdio.h>
int main()
{
int i;
for (i = 0; i < 10; i++)
{
int j;
j = i * 10;
printf ("%d * 10 is %d\n", i, j);
}
return 0;
}
Here, j is declared within the for loop, and therefore it's scope is limited to that code block.
Is this good programming style? Well, that's another conversation that I'm sure someone will argue to death in a 50 post long thread, but imho, if it suits your needs, use it.