c - C内存棋盘游戏错误:读取访问冲突
问题描述
我正在对使用 C 语言创建的游戏进行一些改进。该项目是一个记忆棋盘游戏,其中有 2 个表格,一个数字表格和一个字母表格,玩家必须选择 2 个具有匹配字母的数字。
数字表是一个字符数组,每次正确猜测后,表中的数字都会被替换为字母表中的相应字母。
该错误发生在程序应该打印数字数组的函数的一部分中。(我已将形式数组参数大小设置为 8x8 以适应所有级别的游戏)。
玩家在ConditionCheck函数中选择数字,程序确保该数字有效。
void NumInput(char numbers[8][8], int rows, int columns)
{
int i, j, n1, n2;
printf("Choose 2 numbers from the table below: \n\n"); /// print the numbers array
for (i = 0; i < rows; i++)
{
for (j = 0; j < columns; j++)
if (isalpha(numbers[i][j]) != 0) // if the array literal is a letter
printf("%2c ", numbers[i][j]);
else
printf("%2d ", numbers[i][j]);
printf("\n\n");
}
n1 = ConditionCheck(1, rows * columns);
n2 = ConditionCheck(2, rows * columns);
N1 = &n1;
N2 = &n2;
return;
}
这就是我得到的地方:读取访问冲突。第 8 行中的数字是 0x11100DE(如果选择)
我做错了什么?
编辑:我已经在主游戏函数中初始化了数组。
char numbers[9][9];
k = 1;
for (i = 0; i < rows; i++) /// initializing 'numbers' array
for (j = 0; j < columns; j++)
{
numbers[i][j] = k;
k++;
}
我稍后在同一个主游戏函数中调用了函数NumInput几行:
while (countdown >= 0 && !win)
{
time1 = clock();
NumInput(numbers[rows][columns], rows, columns);
num1 = *N1;
num2 = *N2;
注意: N1和N2是整数指针,用于访问玩家在NumInput函数中选择的数字
解决方案
推荐阅读
- android - 删除签名验证会自动授予运行时权限吗?
- python - 在 SQLAlchemy 中引用表名和列名
- google-analytics - utm_source 和 utm_medium 在 SPA 中丢失
- css - 如何在 R Shiny 应用程序中左对齐乳胶方程?
- css - 进度条从父容器外部开始
- vhdl - 在 for-generate 语句中为信号赋值
- excel - 如何将所有数据(将单元格限制为 72 个字符)复制到新工作簿中?
- java - 选择器不打开视频
- python-3.x - 获取 Kivy 中窗口的位置
- ios - 从 RootPageViewController 调用按钮会导致错误