Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. creating an array of the corect size

creating an array of the corect size

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structurestutorial
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johnstonsk
    wrote on last edited by
    #1

    I am trying to create an array of structures (struct TSimSignal) that are of the size of SignalCount in the TSimHeader struct Below is the structure that I have created: struct TSimSignal { double Value[45]; int SimWriteFlag; int data_index; int DisplayReadFlag; long TimeStamp; }; struct TSimHeader { char *Name[45]; char *Unit[45]; double Min[45]; double Max[45]; int SignalCount; int SimStatus; }; //this is what I am trying to do struct TSimSignal signal_str[TSimHeader.SignalCount]; int *data_index_ptr[TSimHeader.SignalCount]; double *data_ptr[TSimHeader.SignalCount]; How can I create these arrays with the size of SignalCount? I know that I have to have a const to set the size of the array, but not sure how to make the const = to SignalCount; SignalCount is set when A file is read in. It does a count and then sets the number for SignalCount. thanks,:) sj

    D 1 Reply Last reply
    0
    • J johnstonsk

      I am trying to create an array of structures (struct TSimSignal) that are of the size of SignalCount in the TSimHeader struct Below is the structure that I have created: struct TSimSignal { double Value[45]; int SimWriteFlag; int data_index; int DisplayReadFlag; long TimeStamp; }; struct TSimHeader { char *Name[45]; char *Unit[45]; double Min[45]; double Max[45]; int SignalCount; int SimStatus; }; //this is what I am trying to do struct TSimSignal signal_str[TSimHeader.SignalCount]; int *data_index_ptr[TSimHeader.SignalCount]; double *data_ptr[TSimHeader.SignalCount]; How can I create these arrays with the size of SignalCount? I know that I have to have a const to set the size of the array, but not sure how to make the const = to SignalCount; SignalCount is set when A file is read in. It does a count and then sets the number for SignalCount. thanks,:) sj

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      struct TSimSignal *signal_str = new struct TSimSignal[TSimHeader.SignalCount]; int *data_index_ptr = new int[TSimHeader.SignalCount]; double *data_ptr = new double[TSimHeader.SignalCount];

      D J 2 Replies Last reply
      0
      • D David Crow

        struct TSimSignal *signal_str = new struct TSimSignal[TSimHeader.SignalCount]; int *data_index_ptr = new int[TSimHeader.SignalCount]; double *data_ptr = new double[TSimHeader.SignalCount];

        D Offline
        D Offline
        Dean Goodman
        wrote on last edited by
        #3

        And don't forget to call delete on the pointers when you are done with the arrays, i.e.delete []signal_str; delete []data_index_ptr; delete []data_ptr;
        -Dean

        J 1 Reply Last reply
        0
        • D Dean Goodman

          And don't forget to call delete on the pointers when you are done with the arrays, i.e.delete []signal_str; delete []data_index_ptr; delete []data_ptr;
          -Dean

          J Offline
          J Offline
          johnstonsk
          wrote on last edited by
          #4

          Thanks Dean, sj:)

          1 Reply Last reply
          0
          • D David Crow

            struct TSimSignal *signal_str = new struct TSimSignal[TSimHeader.SignalCount]; int *data_index_ptr = new int[TSimHeader.SignalCount]; double *data_ptr = new double[TSimHeader.SignalCount];

            J Offline
            J Offline
            johnstonsk
            wrote on last edited by
            #5

            David, I get the same error when I try it this way. Any ideas? d:\....h(42) : error C2275: 'TSimHeader' : illegal use of this type as an expression d:\....h(19) : see declaration of 'TSimHeader' sj:confused:

            J 1 Reply Last reply
            0
            • J johnstonsk

              David, I get the same error when I try it this way. Any ideas? d:\....h(42) : error C2275: 'TSimHeader' : illegal use of this type as an expression d:\....h(19) : see declaration of 'TSimHeader' sj:confused:

              J Offline
              J Offline
              johnstonsk
              wrote on last edited by
              #6

              Figured it out, I just made a pointer to the structure and accessed the data using the pointer sj

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups