Dynamically resizing array implemented in C