Find the answer to your Linux question:
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]; ...
  1. #1
    Just 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.

    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];
    say i have the above structure, how do i access the different variables inside?

    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!

  2. #2
    Just Joined!
    Join Date
    May 2007
    Posts
    2
    I did a few more readings and changed my code a lil,

    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];
    I'm still not sure regarding accessing the data using the array.

  3. #3
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    try;

    buf_node[1].ifindex[1] = 123;
    fprintf(stdout, "ans->%d\n", buf_node[1].ifindex[1]);

    if MAX_NODE >= 1

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    try this tutorial...it has a very simple intro to structures and arrays of structures...

    Brian W. Kernighan: Programming in C: A Tutorial

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...