I am having trouble with free. I want to allocate a 2d array of *chars and free them, but it fails at runtime. I am learning pointers and probably over complicating this.
//NUMBEROFLINES, NUMBEROFDIE, and WIDTHOFDIE are some ints (3, 2, 3),
int iLineSize, iLine, iDie;
char **piDieString;
piDieString = (char**)malloc(NUMBEROFLINES * sizeof(*piDieString)); //Allocate number of lines
iLineSize = NUMBEROFDIE * WIDTHOFDIE * sizeof(char); //Size of line
for(iLine = 0; iLine < NUMBEROFLINES; iLine++)
{
piDieString[iLine] = (char*)malloc(iLineSize); //Allocate size of lines
}
//Stuff happens
/*Freeing*/
for(iLine = 0; iLine < NUMBEROFLINES; iLine++)
{
free(piDieString[iLine]);
}
free(piDieString);