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

struct thing {
    int part1;
    double *part2;
};

struct thing *setValue (struct thing *t, int pos, double set){
    if (t->part1 < pos){ // check to see if array is large enough
        t->part2 = realloc (t->part2, (pos+1) * sizeof(double)); /* assume no error */
        for (int a = t->part1 + 1; a < pos + 1; a++)
            t->part2[a] = 0;
        t->part1 = pos;
    }
    t->part2[pos] = set; // ALWAYS stores an integer, don't know why
    return t;
}

int main(void) {
  struct thing *abc;
  abc = malloc(sizeof(struct thing)); /* assume no error */
  abc->part1 = 0;
  abc->part2 = malloc(sizeof(double)); /* assume no error */
  setValue(abc, 42, 4.2);
  setValue(abc, 4, -0.04);
  printf("abc's values: %f and %f\n", abc->part2[4], abc->part2[42]);
  return 0;
}