-1

这是我的第二个 C 作业,我们被告知要重新创建康威生命游戏的一个版本。我正在使用 struc (typedef) 来保存我的二维整数数组,用于创建网格:

typedef int TableType[HEIGHT][WIDTH];

HEIGHT & WIDTH 是#define 常量。

我正在尝试使用下面的函数来比较 2 个表格。出现以下错误(无论我以何种方式尝试比较值):

error: expected expression before '==' token


int compareTables (TableType tableA, TableType tableB){
    int height, width;
    for (height = 0; height < HEIGHT; height++) {
        for (width = 0; width < WIDTH; width++) {
        if(tableA[height][width]) == tableB[height][width])
        return LIFE_NO;
        }
    }
    return LIFE_YES;
}

我正在使用 Code-Blocks 作为我的编译器,但似乎找不到让 gccx 工作的方法。所以,据我所知,“stdio.h”是我唯一可以使用的库。

我尝试过导入指针并使用 -> 运算符操作这些指针以获取要比较的值,但无济于事。我也使用类似的方法来复制表,它似乎编译得很好。

有什么建议么??请温柔,我是noob。

提前致谢。

4

2 回答 2

0
if(tableA[height][width]) == tableB[height][width])

应该

if(tableA[height][width] == tableB[height][width])
于 2012-02-25T07:44:15.450 回答
0

你应该做

   if(tableA[height][width] == tableB[height][width]) 

不是

      if(tableA[height][width]) == tableB[height][width])

你的功能应该是:

int compareTables (TableType tableA, TableType tableB)
{
    int height, width;
    for (height = 0; height < HEIGHT; height++) {
        for (width = 0; width < WIDTH; width++) {
            if(tableA[height][width] == tableB[height][width])
                return LIFE_NO;
        }
    }
    return LIFE_YES;
}
于 2012-02-25T07:45:46.450 回答