Okay, to be honest, I don't know if its the free but thats where, after a lot of printf the code stops working.
First off, I declare in main: unsigned char** imgSet and int n=0.
void loadImage(unsigned char*** imgSet, int *n) {
char fileName[80];
printf("Enter filename: ");
scanf("%s",fileName);
addImage(imgSet,&(*n));
readImage(&fileName,&(*imgSet)[(*n)-1]);
printf("File %s has %d rows and %d columns\n",fileName,(*imgSet)[(*n)-1][0]+1,(*imgSet)[(*n)-1][1]+1);
}
void addImage(unsigned char*** imgSet, int *n) {
unsigned char **temp;
temp = (unsigned char **)malloc(((*n)+1)*sizeof(unsigned char *));
int i;
for(i=0;i<(*n);i++)
temp[i] = (*imgSet)[i];
free((void *)(*imgSet));
(*imgSet) = temp;
(*n)++;
}
I pass to loadImage using: loadImage(&imgSet, &n). My first initial load works, however, when I attempt to load a new image, I get a fault. I actually tried to run thru all the first 2D index at the beginning of each loop iteration in main (eg imgSet[0]). I also get a fault there.
Why can't they just easily explain malloc online? Everything about it is so obtuse, it's ridiculous. Perhaps I'm finding the wrong sites...