Heavy Metal
October 8th, 2002, 10:37 AM
I have declared a dynamic array of strings as thus:
char **testfile;
testfile = malloc(sizeof(char *) * 50);
for(j=0;j<count;j++)
{
testfile[j] = malloc(count * sizeof(char));
}
I am reading strings from a file into the array like this:
j=0;
while(fgets(testfile[j], 80, fp) != NULL)
{
j++;
}
But when I deallocate the dynamic memory like this:
for(j=0;j<count;j++)
{
free(testfile[j]);
counter++;
}
free(testfile);
I get an error message:
Debug Error!
Damage: after Normal Block(#42) at 0x00300180
The thing which is confusing me, if i don't fill the array with values, basically commenting out the lines of code which fill the array, I don't get the error message when I deallocate the memory.
I would truly appreciate any words of wisdom regarding my problem.
Thank you,
TJ
char **testfile;
testfile = malloc(sizeof(char *) * 50);
for(j=0;j<count;j++)
{
testfile[j] = malloc(count * sizeof(char));
}
I am reading strings from a file into the array like this:
j=0;
while(fgets(testfile[j], 80, fp) != NULL)
{
j++;
}
But when I deallocate the dynamic memory like this:
for(j=0;j<count;j++)
{
free(testfile[j]);
counter++;
}
free(testfile);
I get an error message:
Debug Error!
Damage: after Normal Block(#42) at 0x00300180
The thing which is confusing me, if i don't fill the array with values, basically commenting out the lines of code which fill the array, I don't get the error message when I deallocate the memory.
I would truly appreciate any words of wisdom regarding my problem.
Thank you,
TJ