Hi guys, I'm making a program tha thas to open a file, and then store the information from the file into a structure variable, only I can't get the function to work. I can get the program to work if I put the reading of the file in the main function, but it has to be it's own function. Now from my tests (by inserting print statements in the while loop that reads everything from the file) it prints out the correct values. So maybe the problem is in my other functions accessing that information.
Here's the code of the function that reads everything from the file:
void fillStructure(playerData *currentPlayer, playerData playerList[], int count, int invalid[])
{
FILE *inp;
int status;
inp = fopen("bbstats.txt", "r");
status = fscanf(inp, "%s", currentPlayer->name);
while(status != EOF)
{
fscanf(inp, "%d", ¤tPlayer->fieldgoals_att);
fscanf(inp, "%d", ¤tPlayer->fieldgoals_made);
fscanf(inp, "%d", ¤tPlayer->freethrows_att);
fscanf(inp, "%d", ¤tPlayer->freethrows_made);
printf("%d ", currentPlayer->freethrows_made);
validateData(*currentPlayer, playerList, count, invalid);
search(playerList, *currentPlayer, count);
status = fscanf(inp, "%s", currentPlayer->name);
count++;
}
}
That print statement there was my test, ignore it.