I try to fill a two dimensional array which I pass to a function but I can't get it to work. Here is my code:
#define ROW 3
#define COLUMN 3
#define EMPTYFIELD ' '
void fillField( char** data, int row, int column );
int main( void )
{
// Two dimensional array
char field[ROW][COLUMN];
fillField( field, ROW, COLUMN );
return( 0 );
}
void fillField( char** data, int row, int column )
{
for( int r = 0; r < row; r++ )
{
for( int c = 0; c < column; c++ )
{
*data = EMPTYFIELD;
data++;
}
}
}
I get the following errors:
In function ‘int main()’:
main.cpp:11:32: error: cannot convert ‘char (*)[3]’ to ‘char**’ for argument ‘1’ to ‘void fillField(char**, int, int)’
fillField( field, ROW, COLUMN );
^
main.cpp: In function ‘void fillField(char**, int, int)’:
main.cpp:21:9: error: invalid conversion from ‘char’ to ‘char**’ [-fpermissive]
data = EMPTYFIELD;
^
Makefile:208: recipe for target 'main.o' failed
make: *** [main.o] Error 1
How can I solve this Problem? I would appreciate any help! Thanks in advance.