I am trying to grow the following array of character arrays:
char input_channel_name[ 20 ][ 36 ];
The number of columns will always be 36, but the number of rows can vary. When I open my file, I can grab the number of channel names as an integer number_of_channels_in
I have tried to convert it to the follow code (with help of Resizing 2D Arrays in C) without luck:
#define ROWS 20
#define COLS 36
main( argc, argv )
char **input_channel_name;
input_channel_name = malloc(sizeof *input_channel_name * ROWS);
if ( input_channel_name )
{
for ( size_t i = 0; i < ROWS; i++ )
input_channel_name[i] = malloc( sizeof *input_channel_name[i] * COLS);
}
get_input_channels:
input_file = fopen( input_name, "rb" )
fread( plotFileHeader.headerFloats, sizeof( float ), 2, input_file );
number_of_channels_in = plotFileHeader.headerFloats[ N_CHAN_SUB ];
add_rows = number_of_channels_in - ROWS;
char **tmp = realloc( input_channel_name, sizeof *input_channel_name * ROWS + add_rows);
if ( tmp )
{
input_channel_name = tmp;
for ( size_t i = 0; i < add_rows; i++ )
{
input_channel_name[ROWS + i] = malloc( sizeof *input_channel_name[ROWS + i] * COLS);
}
}
I keep getting an
error C2143: syntax error : missing ';' before 'type'
when I try to set input_channel_name = malloc
Any ideas?