// get user's input
int ch = getch();
switch (ch)
{
//input a number
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
{
int i = atoi(ch);
g.board[g.y][g.x] = i;
}
}
In the code I was given to add on to, ch was declared as an int. However, the function getch saves input as a string, correct? How can I convert the string ch into an int so I can work with it? I tried to use the atoi() function, but I keep getting these error messages.
sudoku.c: In function 'main':
sudoku.c:247:17: error: passing argument 1 of 'atoi' makes pointer from integer without a cast [-Werror]
/usr/include/stdlib.h:148:12: note: expected 'const char *' but argument is of type 'int'
sudoku.c:252:17: error: expected ';' before 'g'
sudoku.c:244:21: error: unused variable 'y' [-Werror=unused-variable]
cc1: all warnings being treated as errors
No,
getchreads a character and returns an int (you did correctly definechasint). The easiest way to convert it to a real integer is to subtract'0'. So after validatinggetch, you can replace most of your code with: