错误c0000374,已触发断点

时间:2019-06-11 14:52:32

标签: c++

在函数中,在“ while”循环的中间(不在第一个循环中),我得到一个错误:“已触发断点。”在另一台计算机上不会出现该错误。

'product'是我创建的结构 错误在'temp =(product *)malloc(sizeof(product));'行中 当我按继续时,出现下一个错误: “ ConsoleApplication39.exe中0x777C8529(ntdll.dll)的未处理异常:0xC0000374:堆已损坏(参数:0x778058A0)。”

这是函数的代码:

product* CreateProducts(product *head, FILE* out)
{
    char tempname[100];
    FILE* in = fopen("Manot.txt", "r");
    if (in == NULL)
        GetLost("can't open the file");
    product *temp;
    temp = (product*)malloc(sizeof(product));
    if (temp == NULL)
    {
        freelist(head);
        GetLost("error! not enough memory");
    }

    while (fscanf(in, "%s%d%d %c", tempname, &(temp->quantity), &(temp->price), &(temp->primium)) != EOF)
    {
        temp->next = head;
        head = temp;
        if (head->quantity < 0 || head->price<0)
            fprintf(out, "quantity and price should be positive\n");
        else {
            head->productname = (char*)malloc(sizeof(strlen(tempname) + 1));
            if (head->productname == NULL)
            {
                freelist(head);
                GetLost("error! not enough memory");
            }
            strcpy(head->productname, tempname);
            temp = (product*)malloc(sizeof(product));
            if (temp == NULL)
            {
                freelist(head);
                GetLost("error! not enough memory");
            }

        }
    }

    fprintf(out, "the kitchen was created\n");
    return head;
}

0 个答案:

没有答案