P
pete142
Hi folks --
I have a 4-long array t[ ] of
of struct Targets. And a table of
int * in p[ ]. I need to set up
the int * entries in p[ ] such
that each can reference an int
in any member of the Targets t[ ]
array. How to do it?
Much-simplified example:
1. #include <stdio.h>
2. int main(int argc, char* argv[ ]) {
3. int ix;
4. typedef struct { int num1;
int num2;
int num3;
} Targets;
5. Targets t[4];
6.
7. typedef struct { int *number; } Pointers;
8. Pointers *ap;
9. Pointers p[3] = { { &t[?].num1 },
10. { &t[?].num2 },
11. { &t[?].num3 } };
12. ix = 1; // point t[1]
13. // Need to reference t[ix] thru p[2]
14. ap = &p[2];
15. return *ap->number???? which
16. resolves to t[1].num2 ;
17. }
How do I set up the table of pointers in
p[ ] so as to be able retrieve t[ix].num2,
where ix can be 0, 1, or 2?
Thanks!
-- pete
I have a 4-long array t[ ] of
of struct Targets. And a table of
int * in p[ ]. I need to set up
the int * entries in p[ ] such
that each can reference an int
in any member of the Targets t[ ]
array. How to do it?
Much-simplified example:
1. #include <stdio.h>
2. int main(int argc, char* argv[ ]) {
3. int ix;
4. typedef struct { int num1;
int num2;
int num3;
} Targets;
5. Targets t[4];
6.
7. typedef struct { int *number; } Pointers;
8. Pointers *ap;
9. Pointers p[3] = { { &t[?].num1 },
10. { &t[?].num2 },
11. { &t[?].num3 } };
12. ix = 1; // point t[1]
13. // Need to reference t[ix] thru p[2]
14. ap = &p[2];
15. return *ap->number???? which
16. resolves to t[1].num2 ;
17. }
How do I set up the table of pointers in
p[ ] so as to be able retrieve t[ix].num2,
where ix can be 0, 1, or 2?
Thanks!
-- pete