arrays arrays arrays....

This is a discussion on arrays arrays arrays.... within the C++ Programming forums, part of the General Programming Boards category; Hi there, i have a Problem with converting one Array into another. The Starter Array is a vector Template of ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    30

    arrays arrays arrays....

    Hi there,

    i have a Problem with converting one Array into another.
    The Starter Array is a vector Template of a struct, the targetarray is a static float array.
    The Array is needed so i have a common array to put into vtkData.

    Here the piece of Code:
    (Red is the "criticalcode")

    Code:
    #include <stdio.h>
    #include <iostream>
    #include <vector>
    
    struct SimpVec
    {
      float coordx;
      float coordy;
      float coordz;
    };
    
    vector<SimpVec> vecs2;
    
    void pcavis2(vector<SimpVec> vecs2)
    {
      cout << "Starting Visualisation" << endl;
      int i;
      static float vecs2f[][3];
      //ExampleArray
      //static float x[3][3]={{0,0.5,0.7}, {0.3,0.9,0.2}, {1,1,1}};
      //Checking if the given Vector has elements
      cout << vecs2.size() << endl;
      //Put Vectordata into a float array
      for (int j=0; j < vecs2.size(); j++){
        vecs2f[i][0] = vecs2[i].coordx;
        vecs2f[i][1] = vecs2[i].coordy;
        vecs2f[i][2] = vecs2[i].coordz;
      };
      //Create testdata and put Scalars and Points into it
      vtkPolyData *testdata = vtkPolyData::New();
      vtkPoints *testpoints = vtkPoints::New();
      vtkFloatArray *testScalars = vtkFloatArray::New();
      for (i=0; i < vecs2.size(); i++) testpoints->InsertPoint(i, vecs2f[i]);
    .
    .
    .
    The rest is of the code is plain visualisaion and has no meaning in this Problem.

    Thanks in Advance!
    Jan

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    static float vecs2f[][3];

    You are declaring an array with no size. Try this instead:

    static float* vecs2f[3];
    vecs2f[0]=new float[vecs.size()];
    vecs2f[1]=new float[vecs.size()];
    vecs2f[2]=new float[vecs.size()];


    By doing this, you are going to have to reverse the way you access the elements. vecs2f[0][2] will have to be vecs2f[2][0] in my solution. You could also use a vector if you don't want to have to reverse the way you access the elements.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 06:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 03:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 09:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 08:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21