Originally Posted by
Alexander
So wait, how can I continue to put more data in that variable then?
You mean you want to make the array bigger and add more items? Use realloc()
Code:
int* pNums = malloc( sizeof(int) ); /* An array of 1 int. */
pNums[0] = 5;
pNums = realloc( pNums, 3 * sizeof(int) ); /* Now it can hold 3 ints. */
pNums[1] = 10;
pNums[2] = 666;
But of course in real code (not just an example) you'd want to save the result of realloc() to a temporary pointer first and check if it's NULL, otherwise you could have a memory leak if you overwrite your pointer with NULL without freeing it first.