Regarding C typedef struct

Posted by Bruce Duncan on Stack Overflow See other posts from Stack Overflow or by Bruce Duncan
Published on 2013-06-25T21:36:06Z Indexed on 2013/06/25 22:21 UTC
Read the original article Hit count: 146

Filed under:
|

I have multiple instances of typedef struct box so box box1, box box2 etc. The members of the struct are length, width, height etc.

typedef struct 
{
    int width;
    int height;
} box;

box box1;
box box2;

How can I create a function that operates on all the width members of each box instance? My confusion is how do I pass a pointer to a typedef struct member that works across all instances of box. I know how to pass a pointer to a specific instance member like box1.width but how to pass .width and then do

box1.width=value;
box2.width=value;
box3.width=value;

within the function?

© Stack Overflow or respective owner

Related posts about c

    Related posts about struct