Memory Access Issues

I am writing a program that accepts input from a user, and places the input into a dynamic array. The variable counter is used to keep track of the number of elements that have been added to the array and is returned by the following function so that it can be used to iterate through the array. This code will allow me to input one value and on the second value I receive an access viloation error. After doing some debugging I am getting that the value of counter is equal to -33686019 (or garbage) consistently. Am I properly incrementing the variable? I'm sure I'm doing something small but it is my first experience with the use of pointers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
int* getInput(int* pDataInputArray)
{
	cout << "Input positive integer values one at a"
             << " time. A negative value will stop "			 
             << "input." << endl;						
	
        int input;
	int* counter = new int;
	*counter = 0;

	do 
	{
	    cin >> input;
	    *(pDataInputArray + *counter) = input;
	    *counter++;

	    int mod5;
	    mod5 = *counter % 5;


	    if (mod5 == 0)
	    {
	       pDataInputArray = increaseArraySize(pDataInputArray, *counter);
	    }

	} while (input >= 0);

	return counter;
}
++ has higher precedence than *, thus *counter++ means *(counter++). You could fix that with either correctly placed parentheses or ++*counter.
Thank you! I knew it was something small I was missing.
Topic archived. No new replies allowed.