【问题标题】:Compiler does not see my element being added into my array编译器没有看到我的元素被添加到我的数组中
【发布时间】:2015-09-22 15:02:08
【问题描述】:

这是代码的一部分。我一直在尝试编译,但它一直给我这个错误。是不是赋值语句有问题?

ass1cpy.c:在函数“player_data”中:
ass1cpy.c:26:46:警告:变量“分数”已设置但未使用 [-Wunused-but-set-variable]
double average_goals,average_shots,effIndex,score[MAX];

int
player_data(void){
    char name[MAX];
    int maxgames,playerId,games,minutes,goals,shots,assists,yellowCards,
    redCards,checker = 0, i = 0;
    double average_goals,average_shots,effIndex,score[MAX];
    scanf("%d",&maxgames);
    while(scanf("%d %d %d %d %d %d %d %d     %s",&playerId,&games,&minutes,&goals,&shots,
        &assists,&yellowCards,&redCards,name) == 9){
    average_goals = goal_average(goals,games);
    average_shots = shots_average(shots,goals);
    effIndex = effIndex_cal(goals,assists,redCards,yellowCards,games,maxgames);
    if(checker == 0){
        printf("Player %d scored %d goals in %d minutes from %d games\nGoals     per"
            " game: %05.2f\nShots per goal: %05.2f\nEffindex:     %05.2f\n",playerId,
            goals,minutes,games,average_goals,average_shots,effIndex);
    }
    checker = 1;
    score[i] = effIndex
    i++;
        }
        return 0;
}

如何更改它以使其可以编译?

【问题讨论】:

  • 看起来很明显:“警告:变量'score'设置但未使用”
  • 不,它只是告诉你不要使用score 做任何事情。
  • 编译器会看到您将数据添加到 score 数组。它的问题在于您的代码没有使用您添加的数据。
  • 确实编译(除非你没有告诉我们其他事情)。如果你想要一个无警告的编译——为什么不使用分数呢?
  • score[i] = effIndex 缺少 ; 并且以后从未使用过

标签: c arrays double


【解决方案1】:

这不是错误。这是一个警告。它警告您正在分配一个变量,但从未使用过。它警告您这一点,因为这很可能是一个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 2019-09-22
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多