Hi!
Can anyone tell me why this program is giving a debug error with message
"DAMAGE:after normal block(#42) at 0x00430050".
The message is generated on line free(ptr);
I suppose that the problem is connected with the reallocation of memory.
#include<stdio.h>
#include<stdlib.h>
#define DELTA 5
void include(int d,int* p,int n,int k,int flag);
void main(void)
{
int *ptr;
int i=0,digit,koef=1;
ptr=(int *)malloc(DELTA*sizeof(int));
fp=fopen("test.txt", "r"))
do{
fscanf(fp,"%d",&digit);
if (!(i % DELTA))
koef++;
if(i<(DELTA*koef))
include(digit,ptr,i,koef,1);
else
include(digit,ptr,i,koef,2);
i++;
}
}while(!feof(fp));
free(ptr);
}
void include(int d,int* p,int n,int k,int flag)
{
switch(flag){
case 1: *(p+n)=d;break;
case 2: if((p=(int *)realloc(p,k*DELTA*sizeof(int)))==NULL){
printf("Error!Memory not allocated!\n");
exit(1);
}
*(p+n)=d;break;
}
}