繁体   English   中英

运行时错误-C编程

[英]Runtime error - C Programming

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int cases, num1, num2, var, *ptr2, count, i;
    scanf("%d", &cases);
    ptr2 = (int*)malloc(sizeof(int) * cases);
    memset(ptr2, 0, sizeof(int) * cases);
    if (ptr2) {
        for (count = 0; count < cases; count++) {
            scanf("%d", &num1);
            scanf("%d", &num2);
            for (i = 0; i < num1; i++) {
                scanf("%d", &var);
                ptr2[count] += var / num2;
            }
        }
        for (i = 0; i < cases; i++) {
            printf("%d\n", ptr2[i]);
        }
    }
    return 0;
}

这是问题的描述https://a2oj.com/p?ID=17它在VS IDE上运行得很好,但是由于某些原因,当我提交它时,它们的环境给了我运行时错误。

在将'if(ptr2){'与'memset(ptr2,0 ...);'切换后解决 –安德鲁·纳吉布(Andrew Naguib)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM