The lecturer has written several functions to handle a quad tree data structure, all we have to do is access it to print an ASCII image.
The function for uploading the image works fine, but when I try to access the print function, it gives me a seg fault. In dark red is the function call I made.
I guess I did it wrong? Also there is a lot more code, but I just included the bits that concerned this part of the program.
Code:
typedef struct qtnode QTnode;
struct qtnode {
char type;// ' ','*' or INTERNAL
QTnode *ne; // north east quadrant
QTnode *nw; // north west quadrant
QTnode *sw; // south west quadrant
QTnode *se; // south east quadrant
QTnode *out;// zoomed-out image
};
void printImage(QTnode *qt, int dim)
{
char *buffer;
int i;
// reserve memory for file contents
if((buffer = (char *) malloc(dim * dim)) == NULL) {
printf("Error - out of memory.\n");
exit(1);
}
// intialise buffer
for( i = 0; i < dim * dim; buffer[i++] = ' ' )
;
// decode quad tree into image buffer
createBuffer(qt, buffer, 0, 0, dim, dim);
printBuffer(buffer, dim); // print buffer
free(buffer);
}
QTnode *flag;
printImage(flag->type, dimen);