0
#define MAX 10
struct setArray
{
    int item[MAX];
    int count;
};
typedef struct setArray *BitSet;

how should I initialize the elements in the structure?

2
  • 1
    possible duplicate of How to initialize a struct in ANSI C Commented Aug 17, 2014 at 23:13
  • 1
    Aside: 1) typedef struct setArray *BitSet; though legal, is frowned upon in some style guides: Suggest avoid (exceptions exists) creating typedef of pointers. Instead typedef struct setArray BitSet; BitSet *p = malloc(sizeof *p); 2) int for an array size counter is not as portable as size_t count. Commented Aug 17, 2014 at 23:20

1 Answer 1

2

For example

struct setArray s = { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, MAX };

Or

struct setArray s;

for ( int i = 0; i < MAX; i++ ) s.item[i] = i;
s.count = MAX;

Or

BitSet p = malloc( sizeof( *p ) );

for ( int i = 0; i < MAX; i++ ) p->item[i] = i;
p->count = MAX;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.