Hello World!
Let me get straight to the point. Here's the code:
Code:
void readfile(){
char row[55];
int n=0;
if(source_file=fopen("meccs.txt","r"))
printf("1) file succefully opened!\n");
fgets(row,55,source_file);
number_of_games=atoi(&row);
while(fgets(row,55,source_file)){
sscanf(row,"%d%d%d%d%d%s%s",&games[n].round,&games[n].home_final,&games[n].guest_final,&games[n].home_half,&games[n].guest_half,&games[n].home_team,&games[n].guest_team);
n++;
}
}
The first function reads in the data from a file, and puts it into a structure, row by row. The structure deifinition looks like this:
Code:
struct game{
int round;
int home_final;
int guest_final;
int home_half;
int guest_half;
char home_team[20];
char guest_team[20];
};
And the function that does not work as it is supposed to looks like this:
Code:
void get_team(){
int i=0,n=0;
char team_name[20];
printf("Give me a team name:\n");
scanf("%s",team_name);
if(team_name==games[0].home_team)
printf("ok!\n");
}
NOTE: While trying to figure out, what is the problem, I simlified the get_team() function. You are supposed to enter the team name: "Agarak" . The contents of the games[0].home_team is "Agarak", thus the condition should evaluate to true - at least, in my oppinion... games[] is an array of structures, and if I print out the contents with a for loop, it seems to contain all the data correctly... I suspect, that there may be some stray \0 or \n characters in the strings, because of scanf() or sscanf() or fgets(), but I couldn't find proper references, which would shed some light on this matter. Any help ideas would be welcome!