Thread: Problems with multidim array

  1. #1
    Registered User
    Join Date
    Oct 2002

    Problems with multidim array

    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:

    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:

    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]);
    Thanks in advance!


  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    When you are dynamically allocating a multi-dimensional array you should be doing something to this effect.

    //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 subscribe to a feed

Similar Threads

  1. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  2. Have problems with copying my array!
    By AvaGodess in forum C Programming
    Replies: 11
    Last Post: 09-25-2008, 12:56 AM
  3. Problems passing an array to a function
    By ndenklau in forum C Programming
    Replies: 5
    Last Post: 09-20-2006, 08:14 AM
  4. Helllppp!!! I/O and array problems
    By dorky in forum C++ Programming
    Replies: 3
    Last Post: 07-02-2005, 09:24 AM
  5. Creating 2D arrays on heap
    By sundeeptuteja in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2002, 11:44 AM