Hi guys,
We are just learning how to implement calloc, malloc and free. At the end of my program, I keep getting a "windows has triggered a break point" error. Im pretty sure that this error is happening because of the way I am implementing free because this is the error I am getting in free.c - " retval = HeapFree(_crtheap, 0, pBlock);"
here is the code which I allocate and free memory:
Code:
int main (){
WORDS userWords[16];
char **board;
int i=0, n=0, numWords=0;
srand(time(NULL));
numWords = enterWords(userWords);
board = (char **) calloc(20, sizeof(char));
for (i=0; i<20; i++){
board[i] = (char *) calloc(40, sizeof(char));
}
for(i=0; i<20; i++)
{
if(i != 0)
printf("\n");
for(n=0; n<40; n++){
board[i][n] = '0';
printf("%c", board[i][n]);
}
}
inputWords(userWords, board, numWords);
cls;
for(i=0; i<20; i++)
{
if(i != 0)
printf("\n");
for(n=0; n<40; n++){
printf("%c", board[i][n]);
}
}
pause;
populateGameBoard(userWords, board);
displayGameBoard(userWords, board, numWords);
pause;
free(board);
return 0;
}