creating an array of the corect size
-
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 -
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,:) sjstruct TSimSignal *signal_str = new struct TSimSignal[TSimHeader.SignalCount]; int *data_index_ptr = new int[TSimHeader.SignalCount]; double *data_ptr = new double[TSimHeader.SignalCount];
-
struct TSimSignal *signal_str = new struct TSimSignal[TSimHeader.SignalCount]; int *data_index_ptr = new int[TSimHeader.SignalCount]; double *data_ptr = new double[TSimHeader.SignalCount];
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 -
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;
-DeanThanks Dean, sj:)
-
struct TSimSignal *signal_str = new struct TSimSignal[TSimHeader.SignalCount]; int *data_index_ptr = new int[TSimHeader.SignalCount]; double *data_ptr = new double[TSimHeader.SignalCount];
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:
-
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:
Figured it out, I just made a pointer to the structure and accessed the data using the pointer sj