How to rewrite Memo1 to arrays?
Jun 16, 2011 at 12:42pm UTC
How to rewrite the value of Memo1 to 2 arrays?
For example, When in Memo1 I have:
4 3.2
1 9.4
2 3.0
6 3.3
Memo1 sends the values to two arrays, such that:
Tab1[0] = 4
Tab1[1] = 1
Tab1[2] = 2
Tab1[3] = 6
Tab2[0] = 3.2
Tab2[1] = 9.4
Tab2[2] = 3.0
Tab2[3] = 3.3
How to do this?
I tried to do this as follows:
1 2 3 4 5 6 7 8 9 10
int SizeTab = Memo1->Lines->Count;
int * Tab1;
double * Tab2;
for (int i = 0; i < SizeTab; i++)
{
Tab1[i] = StrToInt(Memo1->Lines-> ??? );
Tab2[i] = StrToDouble(Memo1->Lines-> ??? );
}
Please correct it
Jun 16, 2011 at 3:01pm UTC
The first thing I see is that you have only declared a pointer to int and a pointer to double. They don't point to anything yet so referencing Tab1[i] and Tab2[i] will give you an error.
you need to either allocate memory to the pointers as follows:
1 2
Tab1 = new int [SizeTab];
Tab2 = new double [SizeTab];
or make the pointers point to arrays that you have initialised.
After this you can access or asign values to Tab1 and Tab2 arrays.
and after you have used them you can free the memory using delete as follow:
1 2
delete [] Tab1;
delete [] Tab2;
Last edited on Jun 16, 2011 at 3:02pm UTC
Topic archived. No new replies allowed.