So as you know, in C function declarations, you have to name all dimension sizes but one of array parameters. I'm now working with a 2d array where both sizes are generated at runtime, however I want to pass that array to another function to fill it.
My thought was just using the maximum size in the function declaration, like this:
int max_size = 100;
int actual_size;
int another_size;
static void fill_array(int ar[][max_size])
{
for(int i = 0; i < another_size; i++)
{
for(int j = 0; j < actual_size; j++)
{
ar[i][j] = some int;
}
}
}
static void main()
{
if(some_input) actual_size = 50;
else actual_size = 100;
if(some_input) another_size = 10;
else another_size = 20;
int empty_array[another_size][actual_size] = {0};
fill_array(empty_array);
}
My thought is that even though the function may think that each array line has 100 ints, we're only filling the first 50 anyways. Is this unclever? Any way to accomplish the same more cleaner? Pretty new to C, so sorry if it's a very obvious thing.