将struct member-array分配给另一个struct-array

时间:2016-11-25 21:31:28

标签: c struct variable-assignment imperative

我必须将结构定义为:

typedef struct {
  char weekday[WEEKDAY_SIZE], 
       start_time[START_TIME_SIZE], 
       home_team[TEAM_SIZE], 
       away_team[TEAM_SIZE], 
       spectators[SPECTATOR_SIZE];

  int day, month, year, round, home_team_score, away_team_score;
} MATCH;

typedef struct {
  MATCH match[MATCH_PR_ROUND];
} ROUND;

填充主要功能的结构:

ROUND round[33];
MATCH equal_four_goal_matches[198];

我需要在一定条件下为另一个相应的匹配数组分配一个回合(例如一个匹配数组)。

  for(i=0; i<ROUNDS_PR_SEASON; i++) {
    for(j=0; j<MATCH_PR_ROUND; j++) { 
      int match_is_draw = round[i].match[j].home_team_score == round[i].match[j].away_team_score;
      int total_goals = round[i].match[j].home_team_score + round[i].match[j].away_team_score;

      if(match_is_draw && total_goals <= 4) {
        /* Trying to assign each match round[i].match[j] to the new array */
        round[i].match[j] = equal_four_goal_matches[k];
        k++;
        (*length)++;
      }
    }
  }

所以基本上我试图将一个struct-member数组分配给另一个与该成员相同类型的结构数组。

使用printf查看是否有任何内容存储在新结构数组的成员中,但它不包含任何内容。使用ANSI89选项和gcc编译时没有错误。

任何帮助非常感谢

0 个答案:

没有答案