How can I correctly implement a dynamic 2D array in C for my programming assignment