A 1st year comp engin student here >_<... and very noob in C programming. Hope someone could help me solve or enlighten me on how to solve the following problem
Your task is to read in a Sudoku grid (can be a partially completed or a fully completed grid) from a
text file (with 0 to indicate blank cell), decide if the given grid is still valid, i.e. contains no repeated
number! If it is valid, print the grid in a specified format, otherwise, print “Invalid Grid\n”.
The following in the template of the program:
Code:
#include <stdio.h>
int main() {
int sudoku[9][9];
read(sudoku);
if (valid(sudoku))
display(sudoku);
else
printf("Invalid Grid\n");
return 0;
}
(P.S) i am also given a sample suduko text file which is as follows:
0 4 2 9 0 8 0 0 0
0 6 0 0 3 0 0 2 7
0 0 5 0 2 7 0 0 6
0 0 8 4 0 0 0 3 0
0 0 7 0 1 0 6 0 0
0 9 0 0 0 5 1 0 0
5 0 0 8 4 0 9 0 0
2 8 0 0 7 0 0 6 0
0 0 0 6 0 9 2 1 0
(* 3 spacing along the row and 1 spacing along each of the 3 coluumn)
I have basicially 3 main step to complete.
1st step (Read the 9x9 grid):
Create a void function ‘read’ that takes in a 2‐D array of size 9x9 as input (passed by reference).
Function ‘read’ opens and reads in a text file named “sudoku.txt” that contains 9x9 integers
representing digit [0..9]. Blank cells in Sudoku grid are indicated with a ‘0’.
Fill in the 2‐D array, and since this array is passed ‘by reference’, then the updated content will
be reflected in the function that calls ‘read’ (in this case, in the ‘main’ function).
2nd step (check validity of the given suduko grid):
As we know, each row, column, and 3x3 block of a valid Sudoku grid CANNOT have repeated
number! You are guaranteed that the file “sudoku.txt” will never contains any other integer
other than [0..9].
Your task is to create function ‘valid’ that takes in the 9x9 grid read using function ‘read’ above,
and then check if it is valid (that is, no repetition of [1..9], although it is ok to see a repetition of
zeroes that indicates blank cells). If it is valid, returns 1, otherwise, returns 0.
The final step will be(Display the suduko grid):
If the given Sudoku grid is valid, then print it nicely to screen as shown below for the given
“sudoku.txt”
-------------------------
| 0 4 2 | 9 0 8 | 0 0 0 |
| 0 6 0 | 0 3 0 | 0 2 7 |
| 0 0 5 | 0 2 7 | 0 0 6 |
-------------------------
| 0 0 8 | 4 0 0 | 0 3 0 |
| 0 0 7 | 0 1 0 | 6 0 0 |
| 0 9 0 | 0 0 5 | 1 0 0 |
-------------------------
| 5 0 0 | 8 4 0 | 9 0 0 |
| 2 8 0 | 0 7 0 | 0 6 0 |
| 0 0 0 | 6 0 9 | 2 1 0 |
-------------------------

