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

how should I initialize the elements in the structure?

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
yellowcorn
  • 19
  • 3
  • 1
    possible duplicate of [How to initialize a struct in ANSI C](http://stackoverflow.com/questions/330793/how-to-initialize-a-struct-in-ansi-c) – Utkan Gezer Aug 17 '14 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`. – chux - Reinstate Monica Aug 17 '14 at 23:20

1 Answers1

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;
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335