我有一个函数,通过查看数组中的一些匹配项并查找所有符合条件的匹配项的团队。发现时,他们需要分配给一个新的阵列。新数组应该用作输出参数。我打电话给我时得到segmentation fault: 11
。我试图调试,但似乎无法得到原因。以下是主要的声明:分段错误:11
TEAM team_least_viewers;
double spectators = 99999;
solve_task_four(round, team, &team_least_viewers, &spectators);
和函数本身:
void solve_task_four(ROUND *round, TEAM *team, TEAM *team_least_viewers, double *spectators) {
int i, j, k = 0;
for(i=0; i<ROUNDS_PR_SEASON; i++) {
for(j=0; j<MATCH_PR_ROUND; j++) {
if(round[i].match[j].year == 2015) {
/* Searching for team name in team[]*/
for(k=0; k<NUMBER_OF_TEAMS; k++) {
/* If it matches */
if (round[i].match[j].home_team == team[k].name) {
team[k].spectators_home_last_year += round[i].match[j].spectators;
}
}
}
}
for(k=0; k<NUMBER_OF_TEAMS; k++) {
if(team[k].spectators_home_last_year < *spectators) {
*spectators = team[k].spectators_home_last_year;
}
}
}
}
的结构的要求:
typedef struct {
char weekday[WEEKDAY_SIZE], start_time[START_TIME_SIZE],
home_team[TEAM_SIZE], away_team[TEAM_SIZE];
double spectators;
int day, month, year, round, home_team_score, away_team_score;
} MATCH;
typedef struct {
MATCH match[MATCH_PR_ROUND];
} ROUND;
typedef struct {
char *name;
int points, matches_played,
matches_won, matches_draw, matches_lost,
matches_won_home, matches_won_away,
goals_for, goals_against, goal_difference;
double spectators_home_last_year;
} TEAM;
任何帮助是多赞赏。
'if(team [k] .spectators_home_last_year <* spectators)'比较双打不是一个好主意。 – hbagdi
@hbagdi:为什么会比较双打是一个坏主意? –
你可以发布TEAM,ROUND和MATCH结构吗? 另外,如果你想在这里做什么,'round [i] .match [j] .home_team == team [k] .name'不能做字符串比较。 – hbagdi