Help needed with complex array of pointer to structures
Hi,
Imagine the following situation.
Code:
typedef struct{
unsigned short id;
unsigned long val;
unsigned long cap;
}SV;
typedef SV* s_ptr;
then at another place in the program, I make the following variables of the above type:
Code:
SV s[4];
s_ptr s1[2];
s_ptr s2[2];
s[0].id = 1;
s[0].val = 34;
s[0].cap = 50;
s1[0] = &s[0];
s[1].id = 2;
s[1].val = 23;
s[1].cap = 100;
s1[1] = &s[1];
s[2].id = 3;
s[2].val = 45;
s[2].cap = 150;
s2[0] = &s[2];
s[3].id = 4;
s[3].val = 55;
s[3].cap = 250;
s2[1] = &s[3];
As you can see, I create an array of 4 structures of type SV, that is given by SV s[4]. Also, I create 4 pointers to the structure i.e. s1[0], s1[1], s2[0], s2[1].
The structure variables are filled up and then pointers are assigned to point to these structures.
My problem or question is the following. If I need to have an array where I can keep the two pointer arrays i.e. s1 and s2. How do we do it, what is the safe way to do it. Is the following right way to do it ?
Code:
s_ptr* svs[2]
svs[0] = s1;
svs[1] = s2;
Thanks for help and comments.
Sincerely,
Zahid