0

I am so close on the reflect function for pset4. When I run the program it appears to work properly, but it doesn't pass check50. Does anyone know what I am doing wrong?

void swap(RGBTRIPLE *a, RGBTRIPLE *b); // Name helper function for swap

void reflect(int height, int width, RGBTRIPLE image[height][width]) 
{
    for (int i = 1; i < height; i++) 
    {
        for (int k = 1; k < (width / 2); k++
        {
            swap(&image[i][k], &image[i][width - k); // Swap pixel structs
        }
    }
return;
}

void swap(RGBTRIPLE *a, RGBTRIPLE *b) // Details on helper function
{
    RGBTRIPLE tmp = *a;
    *a = *b;
    *b = tmp;
}
1

First, why does k start at 1 and not 0? By starting at 1, the code completely ignores the first pixel on each row.

Ignoring the missing bracket, let's say that k=0. Is image[i][width - k] valid? More specifically, is image[i][width] valid? Why or why not?

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .