// 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;
}
}
在我要添加的代码中,ch 被声明为 int。但是,函数 getch 将输入保存为字符串,对吗?如何将字符串 ch 转换为 int 以便我可以使用它?我尝试使用 atoi() 函数,但不断收到这些错误消息。
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