Results 1 to 4 of 4
hi!
I'm quite confused regarding the idea of structure arrays at the moment and hope someone can help me here.
Code:
typedef struct {
int current_ptr, flag;
unsigned int ifindex[MAX_NODE];
...
- 10-09-2008 #1Just Joined!
- Join Date
- May 2007
- Posts
- 2
Structure arrays confusion
hi!
I'm quite confused regarding the idea of structure arrays at the moment and hope someone can help me here.
say i have the above structure, how do i access the different variables inside?Code:typedef struct { int current_ptr, flag; unsigned int ifindex[MAX_NODE]; rt_table_t rev_rt[MAX_NODE]; u_int16_t weight_buf[MAX_NODE]; u_int16_t rreq_hist[MAX_NODE]; u_int32_t seqno[MAX_NODE]; } buf_node[MAX_NODE];
My first issue here is if I want to access the variables, do I still need to declare a new pointer to the structer, e.g
buf_node *newptr;
or do I just straight away use the array, e.g
buf_node[0].current_ptr = 1;
buf_node[0].current_ptr = 2;
The first one doesn't make sense but I'd really like to clarify my doubts...
Thank you!
- 10-09-2008 #2Just Joined!
- Join Date
- May 2007
- Posts
- 2
I did a few more readings and changed my code a lil,
I'm still not sure regarding accessing the data using the array.Code:struct buf_data { int current_ptr, flag; unsigned int ifindex[MAX_NODE]; rt_table_t rev_rt[MAX_NODE]; u_int16_t wt[MAX_NODE]; u_int16_t rreq_hist[MAX_NODE]; u_int32_t seqno[MAX_NODE]; } buf_node[MAX_NODE];
- 10-09-2008 #3
try;
buf_node[1].ifindex[1] = 123;
fprintf(stdout, "ans->%d\n", buf_node[1].ifindex[1]);
if MAX_NODE >= 1
- 10-09-2008 #4
try this tutorial...it has a very simple intro to structures and arrays of structures...
Brian W. Kernighan: Programming in C: A Tutorial


Reply With Quote