0

I have been stuck on pset4 for a while and when I try to compile my code I now get 3 errors in the reflect function which are:

helpers.c:83:6: error: conflicting types for 'swap' void swap(int *a, int *b) ^

helpers.c:74:13: note: previous implicit declaration is here swap(&temp[0], &temp[3]); ^

Here is my code:

void reflect(int height, int width, RGBTRIPLE image[height][width])
{
    int temp[6];
    int s = 1;
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            temp[0] = image[i][j].rgbtRed;
            temp[1] = image[i][j].rgbtGreen;
            temp[2] = image[i][j].rgbtBlue;
            temp[3] = image[i][width - s].rgbtRed;
            temp[4] = image[i][width - s].rgbtGreen;
            temp[5] = image[i][width - s].rgbtBlue;
            swap(&temp[0], &temp[3]);
            swap(&temp[1], &temp[4]);
            swap(&temp[2], &temp[5]);
            s++;
        }

    }
    return;
}
void swap(int *a, int *b)
{
    int tempB = *a;
    *a = *b;
    *b = tempB;
}

I attempted to used the swap example from the lecture video/sandbox to achieve the reflected image but for some reason it isn't working. Any help is greatly appreciated!

0

You are passing image[i][j] and [image][width - s], which are of type RGBTRIPLE, to a function which takes integer points as an argument. Plus, image[i][j], for example, will pass the value of image[i][j], not the address. To pass the address, you must use the '&' operator.

| improve this answer | |
  • Ok so I changed my code with your suggestions but can't figure out why it isn't working. I know I can swap the values by using an equalization but I saw someone else do that so I am trying to figure it out my own way using the example from class. – ayeeitsalpha May 24 at 0:16
0

Ok so I had to declare the swap function in the beginning of the reflect function in addition to the end! My code now compiles and I realize all my mistakes were very small overlooked issues. New code:

void reflect(int height, int width, RGBTRIPLE image[height][width])
{
    void swap(int *a, int *b);
    int temp[6];
    int s = 1;
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            temp[0] = image[i][j].rgbtRed;
            temp[1] = image[i][j].rgbtGreen;
            temp[2] = image[i][j].rgbtBlue;
            temp[3] = image[i][width - s].rgbtRed;
            temp[4] = image[i][width - s].rgbtGreen;
            temp[5] = image[i][width - s].rgbtBlue;
            swap(&temp[0], &temp[3]);
            swap(&temp[1], &temp[4]);
            swap(&temp[2], &temp[5]);
            s++;
        }

    }
    return;
}
| improve this answer | |

You must log in to answer this question.

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