When i run this program i get the error segamentation fault (core dumped). I have checked my placeholders several times and can't seem to find the error.
Can anyone tell me what causes segmentation fault. And if any of you have the time feel free to see if you can't find the error i've made.
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define max_number_of_matches 198
struct match {
int round;
char day[3];
char time[5];
char hometeam[3];
char awayteam[3];
int hometeam_score;
int awayteam_score;
};
typedef struct match match;
void read_resultater(const char *filename, match matches[]){
FILE *fp;
char day_m[3], time_m[5], hometm[3], awaytm[3];
int i, rnd, hometm_score, awaytm_score, scanres;
match local_match;
fp=fopen(filename,"r");
scanres = fscanf(fp, "%d %s %s %s - %s %d - %d", &rnd, day_m, time_m, hometm, awaytm, &hometm_score, &awaytm_score);
while (scanres ==7){
local_match.round = rnd;
strcpy(local_match.day, day_m);
strcpy(local_match.time, time_m);
strcpy(local_match.hometeam, hometm);
strcpy(local_match.awayteam, awaytm);
local_match.hometeam_score = hometm_score;
local_match.awayteam_score = awaytm_score;
matches[i] = local_match;
scanres = fscanf(fp, "%d %s %s %s - %s %d - %d", &rnd, day_m, time_m, hometm, awaytm, &hometm_score, &awaytm_score);
i++;
}
fclose(fp);
}
void print_match(match m){
printf("%d %s %s %s - %s %d - %d \n", m.round, m.day, m.time, m.hometeam, m.awayteam, m.hometeam_score, m.awayteam_score);
}
int main(void){
int i;
match matches_SAS_2009[max_number_of_matches];
read_resultater("resultater.txt", matches_SAS_2009);
for(i=0; i <= 198; i++){
print_match(matches_SAS_2009[i]);
}
return 0;
}