Hi to all,
I assume that the given context asks for using C and not C++.
Who has to work with 2D, 3D arrays and subarrays in C on a
regular basis may find the treatment of these topics in
Press, Teukolsky,Vetterling,Flannery: Numerical Recipes in C,
Cambridge University Press
useful.
Who is willing to switch to C++ is in paradise yet:
#include <vector>
using std::vector;
int main()
{
int i,,j,lin=3, col=4;
vector< vector<int> > vector2D(lin, vector<int>(col));
// constructor call, destruction is automatic
for(i=0; i<lin; i++)
for(j=0; j<col; j++)
vector2D[i][j] = i + j;
// what follows does not belong to the paradise I spoke about
for(i=0; i<lin; i++){
for(j=0; j<col; j++){
printf("%d\t", vector2D[i][j]);
}
printf("\n");
}
system("PAUSE");
return 0;
}
Regards,
Ulrich
|