So in this CS50 problem you're given a Sudoku board filled with numbers from 0-9. 1-9 slots needs to be made unchangeable, 0 slots are rendered as '.', and can be changed to a number by hitting any numbers by moving your cursor with up down left right arrow over the slot then hitting any numbers from 1--> 9, you're allowed to delete numbers in the original 0 spots.
I've successfully implemented: Moving the cursor Prevent user from inputting numbers on slots without '.' Deleting numbers in general.(user can still delete numbers from the original board)
Since the original 2d array g.board[][] is changed when user make changes to the board, I copied g.board[][] to g.ogboard[][] and check whenever the user attempts to delete a if the spot the cursor is over(y,x value) on g.ogboard[][] is a originally a blank(0) if it is, change current spot on g.board to 0 else don't.
I've no idea why this method doesn't work, numbers on the orignal board can still be deleted. here's the snippets of code I mention and the entire .c file on pastebin.
Pastebin: https://pastebin.com/raw/hbSz2ypp
Snippet:
//fill g.ogboard
for(int i = 0; i<9; i++)
{
for(int j = 0; j<9; j++)
{
g.ogboard[j][i] = g.board[j][i];
}
}
//handles 1-9 input
case '1'...'9':
if(g.board[g.y][g.x] == 0)
{
g.board[g.y][g.x] = ch - '0';
}
draw_numbers();
break;
//handles delete
case '0':
case '.':
case KEY_ENTER:
case KEY_DC:
case KEY_BACKSPACE:
if(g.ogboard[g.y][g.x] == 0)
{
g.board[g.y][g.x] = 0;
draw_numbers();
}
break;