Move fclose(infile) higher in the file