如何解决C代码中"runtime error exitcode 6"报告的错误?

how to resolve the reported error "runtime error exitcode 6" in C code?

本文关键字:exitcode error runtime 报告 错误 何解决 解决 代码      更新时间:2023-10-16

我在OJ系统上进行了多次代码测试,结果在特定的第三次和第四次运行中不断报告错误"运行时错误exitcode 6",一次测试包含10次运行。除了这两次运行失败外,其他都是正确的。

我在网上检查了"运行时错误exitcode 6"的意思是"无效的文件句柄",但我甚至没有文件变量或引用file的任何进程。

我试图删除不必要的头文件,只留下两个头文件:#include <stdio.h> #include<string>但没有奏效。所以也许你们中的一些人可以帮我离开这里。非常感谢。。。我用C.

这是我的代码

    scanf("%dn",&n); 
    int *A = new int[n];
    for(i = 1; i<n+1; i++) {
        scanf( "%d ",&A[i]); 
    }
    scanf( "n"); 
int *A = new int[n];
for(i = 1; i<n+1; i++) {
    scanf( "%d ",&A[i]); 
}

A的合法索引范围是[0,n-1],而不是[1,n]。因此,该循环的最后一个scanf()写入阵列边界之外。

相关文章: