can someone help? i'm trying to create a function for reading a 2D array and then display it in int main(). i get the following error when running the code: "error: invalid types ‘int[int]’ for array subscript" on the line with cin >> v[i][j].
i'm confused because this seems to work with 1D arrays ( f(&v[0]) and void f(int* v, int* n)) so why wouldnt it work in this case as well?
#include <iostream>
using namespace std;
void f(int* v, int* n, int* m)
{
cin >> *m >> *n;
int i, j;
for(i=0; i<*m; i++)
for(j=0; j<*n; j++)
{
cin >> v[i][j];
}
}
int main()
{
int i, j, m, n, v[10][10];
f(&v[0][0], &n, &m);
for(i=0; i<m; i++)
{ for(j=0; j<n; j++)
cout << v[i][j] << " ";
cout << endl;
}
return 0;
}