You are looping all the way though the new, bigger array size. But the old array isn't that big. So you are getting a bunch of garbage values when you go past the size of the original array. Look here:
for (int i=0; i<active_size; i++)
*(tempPtr + i) = *(uaptr + i);
You are looping all the way to the end of the new size, active_size
. But uaptr
is only the size that maxSize
was at the start, which is 25. So when your reach numbers past 25, you start pulling data from... who knows?
Your copy loop should only go to the size of the original array, or 25 in this case. You don't store that size anywhere, so you need to store it is a variable. old_size
. And then loop only that far when copying:
for (int i=0; i<old_size; i++)
*(tempPtr + i) = *(uaptr + i);