hello experts,
In my previos post, alot of help was givin, but still i cant figure this out. I have a function as described here under, and the problem with this code is found in the for loop as indicated by the compiler.
void ReadHighScores(FILE *Scores,int *elements, player_t *playersData)
{
Scores = fopen("Scores.txt","r");
int temp,i;
player_t *playersTemp;
fscanf(Scores, "%d\n", elements);
playersTemp = (player_t*)realloc(playersData,(*elements) * sizeof(player_t));
playersData = playersTemp;
free(playersTemp);
for(i=0; i<(*elements); i++ )
{
fscanf(Scores, "%s", playersData[i].Name);
fscanf(Scores, "%d", &playersData[i].Score);
}
fclose(Scores);
}
I am calling this function from the main as shown in the code below:
player_t *players;
players = (player_t*)malloc(1 * sizeof(player_t));
ReadHighScores(&Scores,&elements,&players);
for(i=0; i<(*elements); i++ )
{
printf("%s\n",players[i].Name);
printf("%d\n",players[i].Score);
}
The struct that am using:
typedef struct
{
char Name[name_l];
short Score;
}player_t;
All help will be greatly appreciated. Thanks Experts