# Thread: Problems with multidim array

1. ## Problems with multidim array

Hello,
i had some problems lately with that and posted here and got some good solutions. I am now at the end and getting a segmentationfault and i know where the error is but i don't know how to work around it.

The example code says:

Code:
```static float x[3][3]={{0,0.5,0.7}, {0.3,0.9,0.2}, {1,1,1}};
for (i=0; i < 3; i++) {
testpoints->InsertPoint(i, x[i]);
};```
I changed it to my need, but is there a way to make it like the examplecode?

Here is my code:

Code:
```void pcavis2(vector<SimpVec> vecs2)
{
int i;
static float (*vecs2f)[3] = new float[vecs2.size()][3];
for (int j=0; j < vecs2.size(); j++){
vecs2f[j][0] = vecs2[j].coordx;
vecs2f[j][1] = vecs2[j].coordy;
vecs2f[j][2] = vecs2[j].coordz;
};
for (i=0; i < vecs2.size(); i++) {
testpoints->InsertPoint(i, vecs2f[i]);
};```

Jan

2. When you are dynamically allocating a multi-dimensional array you should be doing something to this effect.

Code:
```//note they way I wrote this
float *array[3];
for(int i = 0; i < 3; i++)
array[i] = new float[3];```
This gives you a 3x3 array

Popular pages Recent additions