我有一個函數,通過查看數組中的一些匹配項並查找所有符合條件的匹配項的團隊。發現時,他們需要分配給一個新的陣列。新數組應該用作輸出參數。我打電話給我時得到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