我正在制作一个解决一个数独游戏的程序,但我收到了一个错误,从我的编译器.

error: invalid use of undefined type ‘struct Square’
   30 |         if(box->squares[x]->possible[number-1] == 0){
                                  ^~

功能是:

int updateBoxes(Square *** sudoku, int row, int column){
    int x;
    int number = sudoku[row][column]->number;
    Box * box;
    box = sudoku[row][column]->box;

    for(x = 0; x < SIZE_ROWS; x++){
        if(box->squares[x]->possible[number-1] == 0){
            box->squares[x]->solvable--;
            box->squares[x]->possible[number-1] = 1;
        }
    }
    return 1;
}

错误也出现在后面两行.

SquareBox的定义是:

typedef struct box
{
    struct Square ** squares;  /* array of Squares */
    int numbers;
    int possible[9];
    int solvable;
    struct Box * next;
} Box;

/* square is a single number in the board */
typedef struct square
{
    int number;     
    int possible[9];
    /*
       the array is only made of 0 and 1
       each index corresponds to a number: ex: index 4 == number 5 ...
       1 tells me that 5 cannot go into this scare
       0 tells me that 5 can go into this scare
    */
    int solvable;   /* will be subtracted 1 each time and when it is 1 it's because is solvable */
    Box * box;      /* tells me the corresponding box */
    int row;
    int column;
} Square;

我在YouTube上遵循一个教程,这个家伙没有得到我得到的错误,YouTube视频是: https://www.youtube.com/watch?v=CnzrCBLCDhc&t=1326s

推荐答案

你用了struct Square,而你应该用Box定义中的struct square.更正:

typedef struct box {
    struct square** squares; /* array of Squares */
//         ^
    int numbers;
    int possible[9];
    int solvable;
    struct box* next; // box, not Box
} Box;

另一个选项是在Box之前使用typedef Square,在Box中使用Square:

typedef struct square Square;
typedef struct box Box;
struct box {
    Square** squares; /* array of Squares */
    int numbers;
    int possible[9];
    int solvable;
    Box* next;
};

请注意,在这些定义之后,没有什么叫做struct Square的东西.有struct squareSquare.

C++相关问答推荐

漏洞仅出现在FreeBSD上,但在Windows、Linux和MacOS上运行得非常好

为什么PLT表中没有push指令?

不同到达时间的轮询实现

C指针算法在函数参数中的应用

如何一次获取一个字符

在 struct 中强制转换空指针

如何在C中打印包含扫描字符和整数的语句?

为什么中断函数会以这种方式影响数组?

在C++中父进程和子进程中的TAILQ队列同步问题

在libwget中启用Cookie会导致分段故障

如何使用唯一数字对整型进行分区

这段代码用于在C中以相反的顺序打印数组,但它不起作用

C程序向服务器发送TCPRST

使用正则表达式获取字符串中标记的开始和结束

隐藏测试用例无法在c程序中计算位数.

按字典顺序打印具有给定字符的所有可能字符串

如何不断地用C读取文件?

C 语言中 CORDIC 对数的问题

GnuCobol 使用 double 类型的参数调用 C 函数

获取 struct 中匿名 struct 的大小