Pointers with dynamic memory allocation compile issue?

I checked around the forms a bit and just reread about pointers really. I still couldn't figure out what the problem with this small piece of code is. I have looked though it a few times to the best of my knowledge it doesn't like the apostrophe. Could this have to do with my compiler or O.S.? I'm currently running a Ubuntu distro with a CodeBlocks ide. Thanks guys and sorry if I'm goofing about something stupid.

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
30
31
32
  #include <iostream>

int main()
{
std::cout << "How many integers do you wish to enter? ";
int InputNums = 0;
std::cin >> InputNums;

int* pNumbers = new int[InputNums]; // allocate requested integers
int* pCopy = pNumbers;

std::cout << "Successfully allocated memory for " << InputNums << " integers" << std::endl;
for(int Index =0; Index < InputNums; Index++)
{
std::cout << "Enter a number " << Index << ": ";
std::cin >> *(pNumbers + Index);
}

std::cout << "Displaying all numbers input: " << std::endl;
for(int Index = 0, int* pCopy = pNumbers; Index < InputNums; Index++)
{
std::cout << *(pCopy++) << " " << std::endl;
}

std::cout << std::endl;

// done with using the pointer? release memory
delete[] pNumbers;

return 0;
}
change line 20 of your code to
for(int Index = 0, * pCopy = pNumbers; Index < InputNums; Index++)

or better:
1
2
pCopy = pNumbers;
for(int Index = 0; Index < InputNums; Index++)
Thanks I should have seen that. Runs like a charm now.
Topic archived. No new replies allowed.