Don't declare a duplicate variable that shadows an existing one; just use the existing one.
Make large array static instead of declaring it on the stack.
Remove duplicate fclose