Invalid Conversion from "int" to "int"

I'm trying to copy an array to another array using pointers (Book exercise). It copies the first number, but not the other 9 in the array. Here is that code:
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
#include <iostream>
using namespace std;
void zero_out_array(int *arr, int n);
void copy_array(int *p1, int *p2);
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int b[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int main() {
cout << "Array one is: ";
for(int i=0;i<10;i++){
     cout << a[i] << " ";
     }
cout << endl;
cout << "Array two is: ";
for(int x=0;x<10;x++){
        copy_array(b,a);
        cout << b[x] << " ";
        }

system("PAUSE");
return 0;
}

void copy_array(int *p1, int *p2){
     *p1++ = *p2++;
     
     }


When I tryied this version I keep getting 'Invalid conversion from "int" to "int"' error.
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
#include <iostream>
using namespace std;
void zero_out_array(int *arr, int n);
void copy_array(int *p1, int *p2);
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int b[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int main() {
cout << "Array one is: ";
for(int i=0;i<10;i++){
     cout << a[i] << " ";
     }
cout << endl;
cout << "Array two is: ";
for(int x=0;x<10;x++){
        copy_array(b[x],a[x]);
        cout << b[x] << " ";
        }

system("PAUSE");
return 0;
}

void copy_array(int *p1, int *p2){
     *p1++ = *p2++;
     
     }


Any idea's on how I could make this work?
closed account (1vRz3TCk)
I keep getting 'Invalid conversion from "int" to "int"' error.

you would get 'Invalid conversion from "int" to "int *'

The result of subscripting the array of ints is an int that you are using as an argument to a function that requires a pointer to an int. You would need to 'take the address' (&) of the array element and pass that to the function.
I should have thought of that. >_< I've done this now but now there is a new problem which I don't know how to fix. I get this now on line 15: Invalid Types 'int[10][int**]' for array subscript '
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
#include <iostream>
using namespace std;
void zero_out_array(int *arr, int n);
void copy_array(int *p1, int *p2);
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int b[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int main() {
cout << "Array one is: ";
for(int i=0;i<10;i++){
     cout << a[i] << " ";
     }
cout << endl;
cout << "Array two is: ";
for(int x=0;x<10;x++){
        copy_array(b[&x],a[&x]);
        cout << b[x] << " ";
        }

system("PAUSE");
return 0;
}

void copy_array(int *p1, int *p2){
     *p1++ = *p2++;
     
     }


I'm sorry for the trouble. I understand how pointers work, I just can't seem to get them to work.
closed account (1vRz3TCk)
Try copy_array(&b[x],&a[x]);
Sure enough, it works now. Once more, I fail to notice the obvious. xD Thanks a lot for the help CodeMonkey.
Topic archived. No new replies allowed.