2D Arrays.

So my book provided me with a function prototype.
void printTable(int rows, int cols, TwoDimArray aTable);
Where the TwoDimArray is
typedef int TwoDimArray[NUM_ROWS][NUM_COLUMNS];
The constants for the indices are 15.
When my program tries to call a matrix variable of this type it errors out.
I have tried telling the function the size of the NUM_COLUMNS. I'm getting a little frustrated. Here is what my code looks like at the moment.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <iomanip>
using namespace std;

const int NUM_ROWS = 15;
const int NUM_COLUMNS = 15;

typedef int TwoDimArray[NUM_ROWS][NUM_COLUMNS];

void populateMatrix (int rows, int cols, TwoDimArray **aTable);
void printTable(int rows, int cols, TwoDimArray **aTable);

int main()
{
    int rows = 1, columns = 1;

    cout <<"Please enter the number of rows: ";
    cin >> rows;
    cout << "\nPlease enter the number of columns: ";
    cin >> columns;

    TwoDimArray aTable[rows][columns];

    populateMatrix(rows, columns, aTable);
    printTable(rows, columns, aTable);
    return 0;
}

void populateMatrix (int rows, int cols, TwoDimArray aTable[][15])
{

for(int i = 0; i < rows; i++)
        for(int j = 0; j < cols; j++)
        {
            cout << "Please enter the aTable[" << i << "] ["<< j <<"]:";
            cin >> aTable[i][j];
            cout << endl;
        }
}

Thank you for any help.
Last edited on
1
2
3
4
5
// your book gave you this:
void printTable(int rows, int cols, TwoDimArray aTable);

// you are doing this:
void printTable(int rows, int cols, TwoDimArray **aTable);


Why did you make it a pointer to a pointer to a 2D array?
I was attempting to get it to pass several different manners, then forgot to clean up before I posted, but I have it figured out now. I'm an idiot. The error happens at line 22. It isn't necessary. Well the declaration is, but the rows, and cols are not.
Topic archived. No new replies allowed.