Ah Quzah if thats what i meant id be back in junior grade now wouldn't I
Cheer Salem the code works for 2d defintion though what i need to do is define 3d arrays
I'm looking to create a 20 20 3 array and im finding out its not all that straight forward as i thought when using pointers and the dynamic memory allocation.
Code:
int main(void)
{
int Row = 20;
int Col = 20;
int i,x;
int ***array;
array = new (int**)[3];
for (int i=0; i < 3; i++)
{
array[i] = new (int*)[Row];
for(int x=0; x < Row; x++)
array[i][x] = new int[Col];
}
for (int i = 0; i < 3; i++)
{
for (int x = 0; x < Row; x++)
delete [] array[i][x];
delete [] array[i];
}
delete [] array;
}
This problem with this is i get a suspicious pointer conversion in function main()
Found some nice 2d code but looks difficult to get a 3d version working for it
Code:
#include <iomanip>
#include <iostream>
const int Col = 4;
void init2D(int A[][Col], int nRows, int nCols);
int main(void)
{
int Row =5;
int (*A)[Col];
A = new int [Row][Col];
init2D(A, Row, Col);
for(int i =0; i<Row; i++){
for(int j=0; j<Col; j++)
cout <<setw(5) <<A[i][j];
cout << endl;
}
}// end main
void init2D(int A[][Col], int nRows, int nCols){
for (int i=0; i< nRows; i++)
for(int j=0; j<nCols; j++)
A[i][j]=6*i;
}
Seems like all arrays in C++ are delat as one huge 1D array
n e one any suggestion where i can go from here to create my 3D array
cheers later