I'm implementing a Sudoku, but I'm having a hard time filling it out.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <stdio_ext.h>
typedef struct grid_info {
int size;
int fields_total;
int* grid;
int rows_mistakes;
int column_mistakes;
int sectors_mistakes;
} grid;
void welcome_screen(grid*);
grid* fill_the_(grid*);
int main(int argc, const char* argv[]) {
grid* sudoku = (grid*)malloc(sizeof(grid));
welcome_screen(sudoku);
fill_the_(sudoku);
printf("Sudoku size: %d\n", sudoku->size);
free(sudoku);
return 0;
}
grid* fill_the_(grid* sudoku) {
sudoku->grid = malloc(sizeof(sudoku->fields_total));
for(int row = 0; row < sudoku->size; row += (sudoku->fields_total / sudoku->size)) {
for(int column = row; column = row + sudoku->size; column++) {
scanf("%d", &sudoku->grid[column]);
}
}
}
void welcome_screen(grid* sudoku) {
printf("Welcome to the sudoku game\n"
"Please enter the number of sudoku: ");
scanf("%d", &sudoku->size);
while (sudoku->size < 2 || sudoku->size >= 10) {
printf("The sudoku grid can only have size of 2 to 9\n"
"Please enter the number of sudoku: ");
scanf("%d", &sudoku->size);
}
sudoku->fields_total = pow(sudoku->size, 2);
}
At the time of populating struct
, it looks like it enters an infinite loop , I do not know if I did it right to get an index on the grid within struct
.