I'm still trying to figure out pointers and dynamic memory. Once the dynamic array reaches a value of five or any multiple thereof, this function is called to increase the size of the array by five. sizeOfOldArray is the size before and oldArray is the pointer to the memory locations. The new dynamic array that is formed is returned so that the pointer to the old array now points to the new array. This will work fine for the first five values. They always output correctly, but the rest are just filled with garbage. Any other functions you may need just let me know and I will post them.
int* getInput(int* pDataInputArray)
{
cout << "Input positive integer values one at a"
<< " time. A negative value will stop "
<< "input." << endl;
int input;
int* counter = newint;
*counter = 0;
do
{
cin >> input;
*(pDataInputArray + *counter) = input;
++*counter;
short mod5;
mod5 = *counter % 5;
if (mod5 == 0)
{
pDataInputArray = increaseArraySize(pDataInputArray, *counter);
}
} while (input >= 0);
return counter;
}
The problem seems to come from that first function since it only ever occurs when the program enters that function. The values are copied correctly as I verified by pinning the variable values through runtime. I think it must deal with the returning of the pointer to the new array. The pointer in the calling function receives the same address as is pointed to by the newArray variable, but does it retain the properties of being an array?