Reputation:
For the reflection code I need to reflect a picture vertically (most left go to most right). But this code below does not change a thing. (I also tried to give up on pointers and use the arrays itself in swap function but did not change a thing either.)
REFLECT:
void swap(RGBTRIPLE* p, RGBTRIPLE* q)
{
RGBTRIPLE* temp;
temp = p;
p = q;
q = temp;
}
// Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width/2; j++)
{
swap(&image[i][j],&image[i][width-1-j]);
}
}
}
Upvotes: 1
Views: 401
Reputation: 3699
Your swap function should change to:
void swap(RGBTRIPLE* p, RGBTRIPLE* q)
{
RGBTRIPLE temp; // use a value temp instead of pointer temp
temp = *p; // you should swap the value that pointer points to.
*p = *q;
*q = temp;
}
If you want to swap the pointers themselves, the function will be as below:
void swap(RGBTRIPLE** p, RGBTRIPLE** q)
{
RGBTRIPLE* temp;
temp = *p;
*p = *q;
*q = temp;
}
Upvotes: 1