Exception thrown at 0x0F45939E (ucrtbased.dll) in SUDOKUCHECKER.exe: 0xC0000005: Access violation writing location 0xCDCDCDCD.
I'm coding in VS Community 2019, and it indicates the error is with the following line:
1 2 3 4 5
for (int i = 0; i < nsquared; i++) {
for(int j = 0 ; j < nsquared; j++) {
std::scanf("%d", &sudoku[i][j]);
}
};
I initialize the matrix as such:
1 2 3
int** sudoku = newint*[nsquared];
for (int i = 0; i < n; i++)
sudoku[i] = newint[nsquared];
I tried using cin >> sudoku[i][j] to get it to work but no luck in there. What should I change? Creating a separate line to scanf the endline (i.e. std::scanf("%d\n", &sudoku[i][nsquared-1]);) didn't work either.
for (int i = 0; i < n; i++) // why is this n and not nsquared?
Since you created the sudoku array with nsquared elements, you should initialize nsquared of then.