0

I have a union:

typedef union element{
    int number;
    char letter;
} Element; // used typedef for faster writing of code

I then went ahead and created an array of unions, limited to 10 unions. Therefore, I have:

Element set[10];

As such, I can input 10 alphanumerical values in the array.

I would now like to create an array of set[10]. Let's call this array aOfSets.

Typing the following produced an error, and I'm not sure how to create such array:

set[10] * aOfSets;

I'd like to allocate more space as the program progresses, so I want aOfSets to be a pointer in order to use malloc(), i.e. I'd like to do something like:

aOfSets = malloc(1 * (set));
aOfSets = realloc(aOfSets, 2 * (set));

Really, my only problem is that I don't know how the array aOfSets can be made into an array of arrays (set[10]).

Is this even possible? Help appreciated. Thanks!

timrau
  • 22,578
  • 4
  • 51
  • 64

1 Answers1

1

Already you probably forgot the typedef

typedef Element set[10];

Then a pointer to array is simply

set *aOfSets;

If you don't want to go through the typedef use

Element (*aOfSets)[10];

which is equivalent.

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177