# Thread: Array Problems? (Im a beginner)

1. ## Array Problems? (Im a beginner)

Code:
```
array[x][y];```
Ok Im able to read in a double array of numbers, and print them out just fine with this code:

Code:
```    for (i=0; i<x; i++){
for(j=0; j<y; j++){
array[i][j] = array[i][j];
printf("%d\n", array[i][j]);
}

j=0;
}```
But when I try to flip the array horizontally, it doesnt work.. this is the code i use:

Code:
```    for (i=0; i<x; i++){
for(j=y-1; j>0; j--){
array[i][j] = array[i][j];
printf("%d\n", array[i][j]);
}

j=y-1;
}```

what should i do to make it flip horizontally?

2. I am adding some variables to your code and assuming some things about what you are wanting to do.

Code:
```    for (i=0; i<x; i++){
for(j=y-1, k = 0; j>=0; j--, k++){
temp = array[i][j];
array[i][j] = array[i][k];
array[i][k] = temp;
printf("&#37;d\n", array[i][j]);
}
}```

3. I should have probably asked... What do you mean by flip them horizontally? Like reverse them along the y-axis?

4. Code:
`array[i][j] = array[i][j];`
this line does absolutely nothing (it moves to and from the same place in the array).

Your line that sets "j = ..." in both of your code-samples is also meaningless.

I'm not sure what you meany "not working", as your code seems to be correct.

--
Mats

5. Originally Posted by master5001
I should have probably asked... What do you mean by flip them horizontally? Like reverse them along the y-axis?
yes along the y axis..

so :

1 2 3
4 5 6

would be

3 2 1
6 5 4

6. Ok well the code I posted does that.

7. So, do you just want to print them back to front, or change the content around so that the content is stored the other way around?

If the latter, then master5001 has answered this (you need a temporary variable to store the value when swapping the locations). Although I think you should only iterate over half of the content, as otherwise you'd end up swapping everything back again.

--
Mats

8. its working now..

it needed to be

j >= 0;

ugh duh

9. Yeah I bolded that part, I wasn't sure if it was noticeable to you. I usually put it in red, but that was not the only problem that I spotted..