I am making a program that solves a sudoku game, but I received an error from my compiler.
error: invalid use of undefined type ‘struct Square’
30 | if(box->squares[x]->possible[number-1] == 0){
^~
the function is:
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;
}
the error also aplies to the next two lines.
the definitions of Square and Box are:
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;
I am following a tutorial on youtube and the guy doesn't get the error that I get, the youtube video is: https://www.youtube.com/watch?v=CnzrCBLCDhc&t=1326s
You've used
struct Squarewhere you should have usedstruct squarein theBoxdefinition. Corrected:Another option is to
typedefSquarebeforeBoxand useSquareinBox:Note that there is nothing called
struct Squareafter these definitions. There isstruct squareandSquare.