How to copy a matrix?
<p>I need copy a matrix that I have set up as M into a new matrix M2 and output that matrix. </p>

<p>How can this be done?</p>

<p>Here's what I tried so far:</p>

<pre><code>#include &lt;iostream&gt;

using namespace std;
#define N 24
void copy(int M[][N], int M2[][N], int ROWS, int COLS)
{
    int r, c;
    M2[r][c]= M[r][c];
    cout&lt;&lt; M2[r][c];
}

void print(int M[][N], int ROWS, int COLS)
{
    int r, c, row, col;
    row= 1;
    col= 1;
    M[row][col] = 2;
    for(r=0; r&lt; ROWS; r++)
    {
        for(c=0; c &lt; COLS; c++)
        {
            if(M[r][c]==0)
            {
                cout&lt;&lt;" ";
            }
            else if (M[r][c]==1)
            {
                cout&lt;&lt; "T";
            }
            else if (M[r][c]==2)
            {
                cout&lt;&lt; "*";
            }
            else
            {
                cout &lt;&lt; M[r][c];
            }
        }

        cout &lt;&lt;endl; 
    }
}

void fill(int M[][N], int ROWS, int COLS, int row, int col)
{
    int r, c;    
    for(r=0; r&lt; ROWS; r++)
    {
        for(c=0; c &lt; COLS; c++)
        {
            if (r == 0 || r == ROWS - 1) {
                M[r][c]=0;
            }
            else if(c == 0 || c == COLS -1) {
                M[r][c]=0;
            }
            else {
                M[r][c]= 1;  
            }
        }
    }
}

int main()
{
    int M[N/2][N];
    int M2[N/2][N];
    int ROWS, COLS;
    int r, c;
    ROWS = sizeof(M) / sizeof(M[0]);
    COLS = sizeof(M[0]) / sizeof(M[0][0]);
    fill(M, ROWS, COLS, 1, 1);
    print(M, ROWS, COLS);
    copy(M, M2, ROWS, COLS);

    return 0; 
}
</code></pre>
