c - multidimensional array: incompatible type assignment -
i have declared array of known size,
typedef struct{ ...... char * buffer[height+1]; //height constant int ......} args; int main{ args * info; info = malloc (sizeof(args)); char* output_buffer[width][height+1]; //width constant int >= 4 output_buffer[2] = malloc (sizeof(char)*char_per_line*(height+1)); // error same below info->buffer = output_buffer[2]; // know it's wrong. incompatible types in assignment ....} numbers arbitrary , used illustration.
what doing assign address of output_buffer[width] info->buffer, , pass info argument thread, generates data array of size height+1; in each slot cstring of length char_per_line. cstrings stored in output_buffer[2].
i confused here isn't output_buffer[2] pointer of type char*[height+1]? why can't assign address of memory malloc it?
also, know cannot assign array array, how can code work in desired way? if solution use char** char*[height+1], how can access info->buffer[height], say?
thanks in advance!
according requirement specifying, need do
/* 2d array of pointers. */ char* output_buffer[width][height+1]; ( int =0; i< width; i++ ) ( int j=0; j <height+1; j++ ) output_buffer[i][j] = malloc (sizeof(char)*char_per_line*(height+1)); and then,
info->buffer[some_value] = output_buffer[some_width][some_height]; i confused here isn't output_buffer[2] pointer of type char*[height+1]? why can't assign address of memory malloc it?
malloc returns single dimensional pointer void* have noted, output_buffer[2] not single dimensional pointer. of type char*[height+1]. [] adds 1 more dimension apart *.
Comments
Post a Comment