-
doh array inversion
How do I get this function to work for arrays with an odd height?
Code:
int invert_array(int ptrarray[width][height],int width, int height)
{
for (int down=0, up=height-1; down<=up; ++down,--up){
for (int forward=0, reverse=width-1; forward < width; ++forward,--reverse){
swap(&ptrarray[forward][down],&ptrarray[reverse][up]);
}
}
}
-
> down<=up
Presumably, on the last (middle) row, down == up
So perhaps
down<up
is the condition
Unless your swap function is so broken that you can't swap an element with itself.
You're not using some dumb xor-ing trick are you?