Programming in C ( with -std=C89), and running into errors trying to pass a character string array into a function.
In main(), I’ve declared the array as follows:
#define ROWS 501
#define COLS 101
void my_function( char **);
...
char my_array[ROWS][COLS];
...
my_function(my_array);
In my_function, I’ve declared the array as:
void my_function( char **my_array )
{
...
}
I’m getting this error:
warning: passing argument 1 of 'my_function' from incompatible pointer type,
note: expected 'char **' but argument is of type 'char (*)[101]
A two-dimensional array of characters is still a character array and would have a prototype of
char *my_array. So just change your function definition to this:Note that this will flatten the array. There are different techniques to keep the two-dimensional-ness of the array, an easy way is to use this alternative prototype:
Which will preserve your array’s dimensions when passed.
char **my_arraymeans something completely different (pointer to an array, for example).