This is wrong:
r->array=calloc(sizeof(char), (length+1));
It should be sizeof(char *)
, since you're allocating space for an array of pointers to char. Or, even better, don't hardcode the type of the array elements at all, and use *r->array
instead:
r->array = calloc(sizeof(*r->array), length+1);
It also feels a little weird that you allocate length+1
elements and then only go up to capacity-1
in getSize()
. I think you just want length
.