Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.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 UVa判断上的运行时错误_C_Runtime Error - Fatal编程技术网

C UVa判断上的运行时错误

C UVa判断上的运行时错误,c,runtime-error,C,Runtime Error,我收到关于问题10189的UVa判断的运行时错误。我真的很努力,但一直找不到错误的原因。 在这个问题中,我们应该找到扫雷舰阵地的提示矩阵。下面是我的代码: #include <stdio.h> int main() { char ch; int row, col, i, j, ans[101][101]; int tot = 0; scanf("%d %d", &row, &col); while (row != 0)

我收到关于问题10189的UVa判断的运行时错误。我真的很努力,但一直找不到错误的原因。 在这个问题中,我们应该找到扫雷舰阵地的提示矩阵。下面是我的代码:

#include <stdio.h>

int main() { 
    char ch;
    int row, col, i, j, ans[101][101];
    int tot = 0;

    scanf("%d %d", &row, &col);

    while (row != 0) {
        tot++;

        for (i = 1; i <= row; i++) {
            scanf("\n");
            for (j = 1; j <= col; j++) {
                ch = getchar();
                if (ch == '*') {
                    ans[i][j] = 1;
                } else {
                    ans[i][j] = 0;
                }
            }
        }        
        for (i = 0; i <= row + 1; i++) {
            ans[i][0] = 0;
            ans[i][col+1] = 0;
        }
        for (j = 0; j <= col + 1; j++) {
            ans[0][j] = 0;
            ans[row+1][j] = 0;
        }

        printf("Field #%d\n", tot);
        for (i = 1; i <= row; i++) {
            for (j = 1; j <= col; j++) {
                if (ans[i][j] == 1)
                    printf("*");
                else {
                    printf("%d", ans[i-1][j-1] + ans[i-1][j] + ans[i-1][j+1] +
                                 ans[i][j-1]   +               ans[i][j+1] +
                                 ans[i+1][j-1] + ans[i+1][j] + ans[i+1][j+1]);
                }
            }
            printf("\n");
        }
        printf("\n");

        scanf("\n%d %d", &row, &col);
    }
    return 0;
}
#包括
int main(){
char ch;
int row、col、i、j、ans[101][101];
int-tot=0;
scanf(“%d%d”,行和列);
while(行!=0){
tot++;

对于(i=1;i如果雷区可能是
100x100
,则应将数组变大一列,变长一行:
ans[102][102]

请注意,您可以通过在读取雷区之前将此数组初始化为0来简化代码:

memset(ans, 0, sizeof ans);

您还应该检查
scanf
的返回值,以检测无效的输入和/或过早的EOF,并避免未定义的行为和无休止的循环。

@EugeneSh。不,对不起。我错误地单击了post按钮。您正在某个地方脱离数组边界。