### I Need Help... [Multi-dimention Arrays & Pointers]

So, where to begin..?
I'll start with the Problem. I've been trying to get my program going but it doesn't work. I think that the Problem results from my non-understanding of the workings of pointers and parameters, but as I'm a basic noobie at this it isn't certain.
My code produces the following:
cannot convert `int (*)[7]' to `int*' for argument `3' to `int MapDisplay(int*, int, int*, int)'

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061`` ``````int MapDisplay (int *temparray1,int length, int *MapArray, int NumCols) { int **UnitInfoArrayCpy; UnitInfoArrayCpy = &temparray1; for (int m; m< length; m++) {std::cout<

Any help, tip, advice, correction and/or constructive criticism would be greatly appreciated.
Last edited on
closed account (Dy7SLyTq)
try just MapArray instead of *MapArray on line 44
@DTSCode Thanks for the response, but it doesn't work...
To be honest I mistyped and the error occurs when I correct it as you suggested. If I try to compile it with an asterisk the program freezes and crashes. (I'll edit the 1st post in this fashion, sry for the confusion)
There's not enough code to reproduce the problem, but based on the error message, you're passing a pointer to an array of seven ints (`int (*)[7]`) to MapDisplay as the third argument (where it expects a pointer to int).

Based on the usage of that pointer `MapArray[temp1 * NumCols + temp2];` inside the function, I assume that MapArray is a 2D array (whose second dimension is 7), and you're reinterpreting it as a 1D array. In that case, the proper call would be:

`MapDisplay (UnitInfoArray, lengthUnitInfo, &MapArray[0][0], nNumCols);`
@Cubbi Thanks a lot for your help.
I've tried to add the missing pieces of the program needed (parts are included from headers).

Taking your advice to heart I tried to alter the call to `MapDisplay (UnitInfoArray, lengthUnitInfo, &MapArray[0][0], nNumCols);`
Sadly the whole program freezes and outputs nothing... I had a similar problem before which I got rid of by fiddling with the pointers yet the 1st error ensued.
Could the freezing be a result of a problem with pointers? Or is something else at fault?
There are other issues. Here's the first one I see inside the function itself:

 ``12`` `````` int **UnitInfoArrayCpy; UnitInfoArrayCpy = &temparray1;``````

This made UnitInfoArrayCpy a pointer to a pointer to the first element of main()'s UnitInfoArray.

 ``123`` `````` for (int i = 0; i <= length; i+ 5) { if (UnitInfoArrayCpy[i+2] != 0)``````

Besides the silly "i+5", which does nothing at all and loops forever, these is an error for any i other than -2: UnitInfoArrayCpy is not a pointer to an element of any array. The only valid access is UnitInfoArrayCpy[0], which is the same as *UnitInfoArrayCpy

Incidentally, Is there a reason you're using arrays and not vectors?
Ok, I see what you mean... at this point I can safely say that my code is extremely way to well... bad to save.
@Cubbi the reason i didn't use vectors is that I had no clue they existed^^. I'll look into them and start redo this part of my program.
Thank you for all your help. I appreciate it a lot. I'll get back to you if I need some more help^^.
Topic archived. No new replies allowed.