Hey all,
I'm trying to read from a file that the user has already named and written to correctly, but when I try to read it, the command prompt window closes. However, my code compiles successfully, and every tutorial I've looked at online is telling me to put in the same code as is in there already. Anyone got any ideas? Here's the code for reading the file:
Code:
void readFiles() {
char choice;
char line[80];
int i = 0;
printf("\nThe file \"%s\" was found. Would you like to load this file? (y/n)", filename);
scanf("%c", &choice);
if (choice == 'y' || choice == 'Y') {
inFile = fopen(filename, "r");
while(fgets(line, 80, inFile) != NULL) {
gets(line);
sscanf(line, "%s%d%d%d%d%d%d%d", theLeague[i].name, &theLeague[i].gamesPlayed, &theLeague[i].gamesDrawn, &theLeague[i].gamesLost,
&theLeague[i].goalsScored, &theLeague[i].goalsConceded, &theLeague[i].points);
i++;
}
}
else {
printf("\nYou chose not to load a file. Returning to menu...\n");
}
}