[Solved] Passing a dynamically allocated 2d character array to a function


Arrays are not pointers, and pointers are not arrays.

The first parameter type says that list is a pointer to an array of char.
cArray isn’t; it’s a pointer to char*.

The second says that list is a pointer to an array of char*, which is even further from cArray.

You need to pass the correct type, char**, and both dimensions:

void sampleFunction(int max_rows, int max_columns, char** list){
    for (int i = 0; i < max_rows; i++)
        for (int j = 0; j < max_columns; j++)
            list[i][j] = 0;
}

sampleFunction(10, 25, cArray);

solved Passing a dynamically allocated 2d character array to a function