#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>


//////////////////////////////////////

typedef struct {

  int group[8];
  uint64_t points;

} BestGroup;

//////////////////////////////////////

typedef struct {
  BestGroup *array;
  size_t used;
  size_t size;
} Array;

void initArray(Array *a, size_t initialSize) {
  a->array = (BestGroup *)malloc(initialSize * sizeof(BestGroup));
  a->used = 0;
  a->size = initialSize;
}

void insertArray(Array *a, int *group_add, uint64_t points_add) {
  // a->used is the number of used entries, because a->array[a->used++] updates a->used only *after* the array has been accessed.
  // Therefore a->used can go up to a->size 
  if (a->used == a->size) {
    a->size *= 2;
    a->array = (BestGroup *)realloc(a->array, a->size * sizeof(BestGroup));
  }

  int i;

  for (i = 0; i < 8; i++)
  {
    a->array[a->used].group[i] = group_add[i];
  }
  a->array[a->used].points = points_add;
  a->used++;
}

void freeArray(Array *a) {
  free(a->array);
  a->array = NULL;
  a->used = a->size = 0;
}

///////////////////////////////////////////////////////////////////////////////

int main()

{
    Array a;
    int i;
    int list[8] = {0, 1, 2, 2, 4, 5, 6, 7};

    initArray(&a, 5);  // initially 5 elements
    for (i = 0; i < 100; i++)
      insertArray(&a, list, i);  // automatically resizes as necessary
    printf("%d\n", a.array->group[1]);  // print 2nd element
    printf("%lu\n", a.used);  // print number of elements
    freeArray(&a);
}