** I'm using a 2D array with 5 columns to store player's name, and an array to store his number (number will be concidered a string). I want to copy data of file into an array, but I'm having a problem when it reaches the 2D array. This is the only function that I'm struggling with. The rest of functions are straight forward. **
typedef struct {
int id;
char team_name[25];
char player_name[5][10];
char player_number[5][2]; // the player's number will be concidered a string
}Team;
// File content:
/*
1234
Real Madrid
Courtois 1
Carvajal 2
Alaba 4
Marcelo 12
-------------------
5678
Paris Saint Germain
Hakimi 2
Ramos 4
Messi 30
Neymar 10
*/
Team copy_data_to_array (Team info[]) {
FILE* ptr;
char read_line[25];
ptr = fopen("team_info.txt", "r");
if (ptr!=NULL)
{
while (!(feof(ptr))) {
fscanf(ptr, "%d", &info[i].id);
char ch = getc(ptr);
fgets(info[i].team_name, 25, ptr);
for (int i = 0; i < 5; ++i) {
for (int j=0; i < 1; ++j) {
fscanf(ptr, "%s %s", info[i].player_name[i], info[i].player_number[i]);
}
}
fgets(read_line, 25, ptr); // to read the line from file
}
fclose(ptr);
}
else {
printf("File cannot be allocated...\n");
}
}