-1

Our Teacher said we have to use a 2-D char array, so I created one with:

char theArray[14][14] = {'a','b','c','d'} // after 'd', it continues 'e','f' ...

afterwards I wanted to send that array into a recursive function (type void) together with two variables that just contain one integer each in my main file I used:

travel(theArray, x, y);

to send the array together with the two variables to the function while my function outside of int main() has

void travel (char theArray[][14], int y, int x){...}

My compiler tells me something with "converting from char to char[14][14] not possible. And I have absolute no idea what it is trying to tell me. So far I though I have to make the "[][14]" to tell the function the size of the array.

And when I remove the [][14] I get the error on my main file that char and char* arn't compatible.

Ive also tried stuff like setting up a link with & and * to get around it somehow but so far it didn't work out. If anyone call tell me what it is, that I'm overseeing - thanks!

Darci
  • 3
  • 3

1 Answers1

1

This works for me (it compiles without an error or warning and it runs):

char theArray[14][14] = {
    {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'},
    {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'},
    "abcdefghijklm", "abcdefghijklm", "abcdefghijklm", "abcdefghijklm", 
    "abcdefghijklm", "abcdefghijklm", "abcdefghijklm", "abcdefghijklm", 
    "abcdefghijklm", "abcdefghijklm", "abcdefghijklm", "abcdefghijklm"};
void travel(char theArray[][14], int y, int x){
  (void)theArray; (void)y, (void)x;
}
int main() { 
  int x = 0, y = 0;
  travel(theArray, x, y);
  return 0;
}

Maybe you are initializing theArray incorrectly. To initialize one element, either specify a string literal ("abcdefghijklm") or a long enough list of characters in braces ({'x', 3, ...}).

pts
  • 80,836
  • 20
  • 110
  • 183
  • Just a list of 196 character constants (e.g. `{ 'a', 'b' ... }`, without the nested braces) would be legal too. – James Kanze Jun 09 '14 at 14:22