复制c中的第五个(20%)int数组

时间:2016-06-04 13:32:23

标签: c arrays copy

我试图将前20%的int数组复制到另一个中,但每次尝试时,VS调试器都会显示此错误:

Anti Virus.exe中0x00DB592A处的未处理异常:0xC0000005:访问冲突读取位置0x00B41000。

这是代码:

/*
regularStr - the full arr
regularLen - its size
mode - what part of the array (first 20% or last)
quickFileLen - a pointer to where to put the shorten array size
*/
int* stringToQuickStr(int* regularStr, int regularLen, int mode, int* quickFileLen)
{
    int i = 0, start = 0;
    *quickFileLen = (regularLen / 5);
    int* quickStr = (int*)malloc(sizeof(int) * (*quickFileLen));
    if (!(quickStr))
    {
        printf("quickStr calloc() ERROR!\n");
        return -1;
    }
    if (mode == FIRST_20)
    {
        for (i = 0; i < *quickFileLen; i++)
        {
            quickStr[i] = regularStr[i];
        }
    }
    return quickStr;
    free(quickStr);
}

在复制之后,程序总是在FIRST_20副本中崩溃。

0 个答案:

没有答案