The program is working like this, but i have problem declaring and calling the functions using pointers in 2D arrays | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The program is working like this, but i have problem declaring and calling the functions using pointers in 2D arrays

In this problem, you are asked to fill a n x n Sudoku box by numbers from the user such that:  The Sudoku box is represented by a square (n x n) matrix. You will be using 2D arrays, so n should be known in compile time.  Your code should be testable for any value of n ≥ 3. To ease testing your code on different values of n (n ≥ 3), define n as a global variable.  All numbers in the box should be in the range [1, n x n] i.e. between 1 and n x n.  Each number between 1 and n x n, can appear only once in the box.  Initially fill the n x n matrix by 0’s  Fill the matrix by reading numbers from the user. You should consider cases where the user input may be invalid, and ask him/her to input a valid number: o If the user input is outside the range [1, n x n]. o If the input is in the range, but the number is already in the box (violates the rule). To determine if the number is already in the box you should use two functions:  foundInRow(int* arr[], int row, int number): checks if number belongs to the specified row in arr.  foundInColumn(int* arr[], int column, int number): checks if number belongs to the specified column in arr.  Print the box after filling it. https://code.sololearn.com/cX6tm5wFmQkU/?ref=app

31st May 2020, 3:53 PM
Hussein.H
Hussein.H - avatar
5 Answers
+ 1
The code has two main() functions - line 4 and line 18. Remove the first one and opening brace, and remove its corresponding return 0 and closing brace at the end (lines 120 and 121). That will allow it to compile and run.
31st May 2020, 6:03 PM
Brian
Brian - avatar
+ 1
The three function prototypes currently look like this: void printArray(int array[][n], int r, int c); bool foundInRow(int* array[], int row, int number); bool foundInColumn(int array[][n], int column, int number); Only foundInRow() needs adjustment. For all three functions you could use the same parameter syntax that is used in printArray(), which is what I would recommend. Or, for academic purposes, you could fix foundInRow to be like this declaration: bool foundInRow(int (*array)[n], int column, int number); You would need parentheses as shown because array brackets [ ] have higher precedence than *. Without parentheses, like int* array[],  it appears as a one-dimensional array of pointers to single integers. The parentheses force the parameter to be a pointer to an array of n ints, as was intended. The column array size must be specified, so be sure to include [n]. Now I hope it is apparent why the equivalent syntax, int array[][n], is better!
1st Jun 2020, 6:17 AM
Brian
Brian - avatar
+ 1
special thanks to you
2nd Jun 2020, 1:19 PM
Hussein.H
Hussein.H - avatar
0
Thanks for responding Actually the problem isn’t this, this was just a mistake happened when I copied the code from the Visual Studio into solo learn code playground
1st Jun 2020, 2:05 AM
Hussein.H
Hussein.H - avatar
0
what I am trying to do is to declare and define functions with pointers pointing to a 2D array, thats where I am struggling
1st Jun 2020, 2:05 AM
Hussein.H
Hussein.H - avatar