Hi all I was wondering how to pass a multidimensional array to a function:
Here is my code:
#include <cstdlib>
#include <iostream>
using namespace std;
void PrintArray (int* array, int n);
int main(){
int SIZE;
cout << "Enter how many records: ";
cin >> SIZE;
int array[SIZE][2];
for (int i =0; i < SIZE; i++){
cout << "Enter an Integer: ";
cin >> array[i][0];
cout << "Enter a user ID: ";
cin >> array[i][1];
}
cout << endl << "The list you put in is: " << endl;
PrintArray(array, SIZE);
system("PAUSE");
}
/* This function prints an Array
Arguments:
array - the array to be printed
n - number of elements in the array
*/
void PrintArray(int* array, int n)
{
int i;
for( i = 0; i < n; i++) {
cout<< array[i][0]<<'\t';
}
cout << endl << endl;
for( i = 0; i < n; i++) {
cout<< array[i][1]<<'\t';
}
}
The error I keep getting is:
cannot convert `int (*)[2]' to `int*' for argument `1' to `void PrintArray(int*, int)'
If it's a single dimension array then it compiles no problem. Please could someone tell me what I'm doing wrong.
Thanks for your time and trouble