C is a far pickier language than C++. strictly speaking in C, this line is illegal
Code:
for (int i = 0; i < n; i++)
There's a chance that your version of GCC will let you get away with it, but in C, all declarations must come before any code - which means the
int i = 0 portion of that for statement needs to change to
i = 0 with your
int i; being declared at the top of main()