passing array to function errors

hello i have errors with this code: (question below)
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
int invbinary(int arr[]) { //binair --> decimaal
	int output=0;
	for (int i=7;i>=0;i--) {
		cout<<arr[i]<<" ";
		if (arr[i]==1) {
			int x=1<<i;
			output+=1<<i;
		} 
	}
	return output;
}

int main() {
...
string out;
		int temp[8];
		cout<<"decrypt what?"<<endl;
		cin>>out;
		for (int i=0;i<out.size();i=i+8) {
			for (int j=0;j<8;j++) {
				temp[i]=out.at(i+j)-48;
                                cout<<temp[i];
			}
                        cout<<endl;
			int x=invbinary(temp);
                ...
}


and i get this as output:

decrypt what?
1100100101010110
11001001
-858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 1 0
 0 0 0 0 0 0 0
01010110
-858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 1 0
 0 0 0 0 0 0 0

as you can see everything is stored correctly in temp[i] but when i pass temp to the function invbinary(int arr[]) its getting totally wrong values could anyone tell me what's going wrong?

thanks in advance, if anything isn't clear feel free to ask.
Last edited on
Shouldn't temp[i] be temp[j]?
o wow... worst mistake ever. thank you alot, it works now.
Topic archived. No new replies allowed.