My 2d array char **buffer is being created. The malloc part works. The realloc part is generating a segmentation error.
These are the 2 functions which do the following;
//sets up the array initially
void setBuffer(){
buffer = (char**)malloc(sizeof(char*)*buf_x);
for(int x=0;x<buf_x;x++){
buffer[x] = (char *)malloc(sizeof(char)*buf_y);
}
if(buffer==NULL){
perror("\nError: Failed to allocate memory");
}
}
//changes size
//variable buf_x has been modified
void adjustBuffer(){
for(int x=prev_x; x<buf_x;x++) {
buffer[x] = NULL;
}
buffer=(char**)realloc(buffer,sizeof(char*)*buf_x);
for(int x=0; x<buf_x;x++){
buffer[x] = (char*)realloc(buffer[x],sizeof(char)*buf_y);
strcpy(buffer[x],output_buffer[x]);
}
if(buffer == NULL){
perror("\nError: Failed to adjust memory");
}
}