Need help with pointer to pointer

Hello Folks,

I have been out of touch with C for a while now. Forgettin some basics. Following code is a simulator of the part of the large code that I am planning to implement. Basically here what it is, i have an array of pointers stored in a structure. I do not know as to how many pointers I will hold this array in the begining. As the code progress I go on adding pointer to the array. I keep a count of how many pointers I added to the array in the structure itself by incrementing it everytime I add a pointer to the array.
Now this is what I am doing (or atleast tryin) in the following code. It's working, but I am not sure if what I am seeing is correct. Can some one help me understand it.

This loop isn't really valid...
It works for you because each of your malloc is being placed adjacent to each other on the heap. You don't technically have any gaurantee that this will happen, so this code will cause a seg-fault on many compilers (my computer crashes on this code).

As stated, all of your reallocation is incorrect. You have one pointer, which you point to an integer you allocate. Then you walk off the end of your pointer, into places you shouldn't, and start allocating space there. That's bad. You need something like this: