SuperSharp
Programmer
Hi there,
I am having problems reading from a file and storing the data in a struct. Basically its a league table and I don't have any problem writing to a file or even reading from it, it just doesn't seem to want to update my struct. Here is the function:
I have the struct in "global" and it seems to work for eveything else:
the p = played, w = won, d = draw etc.
char is the name of the teams.
No matter what I do it just don't store the data from the file into the struct. Any ideas anyone? Any help would be greatly appriciated, thanks very much.
Edd =)
I am having problems reading from a file and storing the data in a struct. Basically its a league table and I don't have any problem writing to a file or even reading from it, it just doesn't seem to want to update my struct. Here is the function:
Code:
void load_table()
{
FILE *in_file;
int count = 0;
in_file = fopen("league.dat", "r");
while ( !feof(in_file) )
{
fscanf(in_file, "%s %d %d %d %d %d %d %d", table[count].name, &table[count].p, &table[count].w,
&table[count].d,&table[count].l, &table[count].f, &table[count].a, &table[count].t);
count++;
}
//test to see if it is reading which is it
fclose(in_file);
printf("\n%s\t\t%d %d %d %d %d %d %d",table [1].name, table[1].p, table[1].w,
table[1].d, table[1].l, table[1].f, table[1].a, table[1].t);
}
I have the struct in "global" and it seems to work for eveything else:
Code:
struct league
{
char name[21];
int p,w,d,l,f,a,t;
}table[12];
char is the name of the teams.
No matter what I do it just don't store the data from the file into the struct. Any ideas anyone? Any help would be greatly appriciated, thanks very much.
Edd =)