Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C内存板游戏错误:读取访问冲突_C_Visual Studio 2017_C Strings - Fatal编程技术网

C内存板游戏错误:读取访问冲突

C内存板游戏错误:读取访问冲突,c,visual-studio-2017,c-strings,C,Visual Studio 2017,C Strings,我正在对我用C语言创建的游戏做一些改进。 该项目是一个记忆板游戏,其中有2个表,一个数字表和一个字母表,玩家必须选择2个数字和匹配的字母 数字表是一个字符数组,每次正确猜测后,表中的数字将替换为字母表中相应的字母 错误发生在函数的某个部分,程序应该在该部分打印数字数组。 (我已将正式数组参数大小设置为8x8,以适应所有级别的游戏) 玩家在ConditionCheck函数中选择数字,程序在该函数中确保数字有效 void NumInput(char numbers[8][8], int rows,

我正在对我用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;
}

注意:N1和N2是整数指针,用于访问玩家在NumInput函数中选择的数字

始终使用背带-防止裤子被夹住请提供一个数字。调试不完整的代码是无效的。至少我们需要了解函数是如何调用的。因此,请提供一个可以重现问题的MVE。我认为二维数组很可能会让你受挫。从您所说的访问冲突发生的位置来看,它看起来像是数组读取,因此您传递给函数的内容与您访问它的方式不一致。您还没有展示如何首先分配这个数组;这个细节非常重要。我添加了更多信息以进一步澄清。我发现奇怪的是,大体上,您将数字声明为[9][9],然后在NumInput[8][8]。另外,行和列的值是什么?
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++;
        }
while (countdown >= 0 && !win)
    {
        time1 = clock();
        NumInput(numbers[rows][columns], rows, columns);
        num1 = *N1;
        num2 = *N2;