In the first part we left off laying the foundations for our dynamic array. Now it’s time to test it, this is the code responsible for that:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
int main() { struct ArrayData *array; array = initArray(); int get; int i; for (i = 0; i > 50; i++) { addElement(array, rand() % 50000); get = getElement(array, i); printf("%d\n", get); } free(array->pointer); free(array); return 0; } |
While working on my C programming skills I wrote a small program to simulate the functionality of dynamic arrays on other languages. That is arrays that grow as you add elements to them instead of having a fixed size. I decided that is has to be reusable and that you should be able to have multiple instances of them, so I structured my code with that in mind.
So this is the file structure: