In the function, in the middle of 'while' loop (not in the first loop), I get an error: 'has triggered a breakpoint.' in another computer the error does not appear.
'product' is a struct I created the error is in line 'temp = (product*)malloc(sizeof(product));' when I press continue the next error appears: 'Unhandled exception at 0x777C8529 (ntdll.dll) in ConsoleApplication39.exe: 0xC0000374: A heap has been corrupted (parameters: 0x778058A0).'
this is the code of the function:
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;
}
User contributions licensed under CC BY-SA 3.0