   How to make array equal a return array
  This is my first time trying to pass arrays to other functions and then return back, and heres what I want: *I didnt post the real file, but cBEGINNINGCAVE is actually completely assigned)char cBEGINNINGCAVE[3][22][80];cBEGINNINGCAVE = movemonster(dl, carX, carY, Xc, Yc, cMAPARRAY);The other function its trying to get to is:#include <iostream>#include <ctime>using namespace std;char movemonster(int cZ, int cX, int cY, int Xc, int Yc, char cMAPARRAY[][22][80]){ if(cX != Xc || cY != Yc) {  for(int y = 0; y < 22; y++)  {   for(int x = 0; x < 80; x++)   {    if(cMAPARRAY[cZ][y][x] == 'g')    {if(y < Yc){ cMAPARRAY[cZ][y][x] == '.'; cMAPARRAY[cZ][y++][x] == 'g';}else if(y > Yc){ cMAPARRAY[cZ][y][x] == '.'; cMAPARRAY[cZ][y--][x] == 'g';}else if(y == Yc){}if(x < Xc){ cMAPARRAY[cZ][y][x] == '.'; cMAPARRAY[cZ][y][x++] == 'g';}else if(x > Xc){ cMAPARRAY[cZ][y][x] == '.'; cMAPARRAY[cZ][y][x--] == 'g';}else if(x == Xc){}    }   }  } } return cMAPARRAY;}return cMAPARRAY should resend back the whole array, but changed. How can I do this?259 C:\Users\Todd\Desktop\Tests\Black Skies Projects\mapdata.cpp incompatible types in assignment of `char' to `char[3][22][80]'^^^ The error i get is on the cBEGINNINGCAVE = movemonster(dl, carX, carY, Xc, Yc, cMAPARRAY); line.And by the way, cMAPARRAY on that line is also another array there, with all the same assignings as cBEGINNINGCAVE. If i remove the cBEGINNINGCAVE = and the return cMAPARRAY, everything works fine and i can read out cMAPARRAY in the other function.   
  The error you get is your function returns a single character, and you are trying to pass a 3 dimensional array of characters to it, I believe this could be fixed fairly pain free by changing the return type to char*.However if you insist upon using arrays for this, I would suggest you change your movemonster function into a void return type and pass a reference/pointer to your cmaparray then whatever changes that are made to it during the function are kept.On top of that you should really comment your code and use source tags as it will improve readability for others when you reach problems like this, for example I don't quite understand the purpose of cBEGINNINGCAVE if you are passing cMAPARRAY into the move monster function.   ;char cBEGINNINGCAVE[3][22][80];cBEGINNINGCAVE = movemonster(dl, carX, carY, Xc, Yc, cMAPARRAY);The other function its trying to get to is:#include <iostream>#include <ctime>using namespace std;char movemonster(int cZ, int cX, int cY, int Xc, int Yc, char cMAPARRAY[][22][80]){if(cX != Xc || cY != Yc){for(int y = 0; y < 22; y++){for(int x = 0; x < 80; x++){if(cMAPARRAY[cZ][y][x] == 'g'){if(y < Yc){cMAPARRAY[cZ][y][x] == '.';cMAPARRAY[cZ][y++][x] == 'g';}else if(y > Yc){cMAPARRAY[cZ][y][x] == '.';cMAPARRAY[cZ][y--][x] == 'g';}else if(y == Yc){}if(x < Xc){cMAPARRAY[cZ][y][x] == '.';cMAPARRAY[cZ][y][x++] == 'g';}else if(x > Xc){cMAPARRAY[cZ][y][x] == '.';cMAPARRAY[cZ][y][x--] == 'g';}else if(x == Xc){}}}}}return cMAPARRAY;}You might want to fix those magic numbers there. Either make a constant for the array indexes or pass in variables with those values and use them. It will help you later on when you come back to edit the code and you see those random numbers staring at you. :D The name of the array is not actually the whole array. It is a pointer to the beginning of the array. Therefore, instead of char movemonster(), use char *movemonster(). Then you can iterate through it with [] indexing.[Edited by - boogyman19946 on May 31, 2010 12:13:12 PM];  Alright I made a few changes, although Im still kind of confused a bit. I changed char movemonster() to char *movemonster (), and the cBEGINNINGCAVE = movemonster() to cBEGINNINGCAVE[1000][22][80] = movemonster(dl, carX, carY, Xc, Yc, cMAPARRAY); instead. Now the only error i get is on the return line, which is return cMAPARRAY[3][22][80]; and the error i get is: 46 C:\Users\Todd\Desktop\Tests\Black Skies Projects\movenemies.cpp invalid conversion from `char' to `char*'. So now Im even more confused. By the way Im only trying to experiment, its not a real game, so I dont care too much how much it hinders me later. Im slowly building a real game but trying to make it as best as possible so I can edit anything later and wont have to change much.   ;Quote:Original post by MAGIgullorksAlright I made a few changes, although Im still kind of confused a bit. I changed char movemonster() to char *movemonster (), and the cBEGINNINGCAVE = movemonster() to cBEGINNINGCAVE[1000][22][80] = movemonster(dl, carX, carY, Xc, Yc, cMAPARRAY); instead. Now the only error i get is on the return line, which is return cMAPARRAY[3][22][80]; and the error i get is: 46 C:\Users\Todd\Desktop\Tests\Black Skies Projects\movenemies.cpp invalid conversion from `char' to `char*'. So now Im even more confused. By the way Im only trying to experiment, its not a real game, so I dont care too much how much it hinders me later. Im slowly building a real game but trying to make it as best as possible so I can edit anything later and wont have to change much.Try:return cMAPARRAY;Your return type is a pointer to an array not an array itself.   ;  Hey,I personally dislike having matrixes defined that way to use in the main program. One of the drawbacks of it is just managing these pointer issues and parameter passing (isn't [][22][80] the ugliest parameter declaring you ever made?)I would suggest defining a Matrix class and passing it as reference or an unidimensional array and a function to find the correct array index. (Or the unidimensional array inside the Matrix class).I for one use a Matrix class which is accessed via operator[] that takes as argument a Coord object, whose contents are the three indexes.   ;Quote:Original post by enunesHey,I personally dislike having matrixes defined that way to use in the main program. One of the drawbacks of it is just managing these pointer issues and parameter passing (isn't [][22][80] the ugliest parameter declaring you ever made?)I would suggest defining a Matrix class and passing it as reference or an unidimensional array and a function to find the correct array index. (Or the unidimensional array inside the Matrix class).I for one use a Matrix class which is accessed via operator[] that takes as argument a Coord object, whose contents are the three indexes.Actually it should be [1000][22][80] as the defining, so ill just do that.@ExcessNeo: I tried to change that already to that, but the error i get THEN is:46 C:\Users\Todd\Desktop\Tests\Black Skies Projects\movenemies.cpp cannot convert `char (*)[22][80]' to `char*' in return. What does the (*)[22][80] mean anyway?   ;  char (*)[22][80] is a pointer to an array of 22 arrays of 80 chars.char *[22][80] on the other hand is an array of 22 arrays of 80 pointers to char, in case you wonder.   ;Quote:Original post by DevFredchar (*)[22][80] is a pointer to an array of 22 arrays of 80 chars.char *[22][80] on the other hand is an array of 22 arrays of 80 pointers to char, in case you wonder.It should point to 1000 arrays of 22 arrays of 80 characters... So whats the problem here?   ;  In C++ arrays aren't first class types, which is a fancy way of saying they act funny. Rather than using arrays directly, consider using a class wrapper around the arrays. One example would be a boost::multi_array, but evenstruct Map {  char data[1000][22][80];};would probably ease your life considerably.   