-3
int getCell(RGBTRIPLE image[i][j]){
int add;
add += image[i][j].rgbtRed;
add += image[i][j].rgbtBlue;
add += image[i][j].rgbtGreen;

return add;

}

void blur(int height, int width, RGBTRIPLE image[height][width])

{
    int red;
    int green;
    int blue;
    int sum;
    float average;

for (int i = 0; i < height; ++i)
{
    for (int j = 0; j < width; ++j)
    {
        if(i == 0 && j == 0){
            sum += getCell(image[i][j]); // itself
            sum += getCell(image[i][j+1]); // right
            sum += getCell(image[i+1][j]); // bottom
            sum += getCell(image[i+1][j+1]); // right
            sum = sum / 4;
            image[i][j].rgbtRed = sum;
            image[i][j].rgbtBlue = sum;
            image[i][j].rgbtGreen = sum;
        }

How do I pass the matrix that is passed into blur to another function called getCell? I'm not sure if I'm doing it correctly.

1 Answers1

1

While your title is about passing arrays to a function, it doesn't seem to be what you want. It seems you want to pass a single RGBTRIPLE.

So all you need is:

int getCell(RGBTRIPLE elem){
    int add = 0;             // Make sure to initialize add
    add += elem.rgbtRed;
    add += elem.rgbtBlue;
    add += elem.rgbtGreen;
    
    return add;
}

Also notice that function local variables are not default initialized. So you need to explicit do the initialization, i.e. int add = 0;

The same applies to sum in the other function, i.e.

int sum; --> int sum = 0;

Also notice that your current code do out-of-bounds access.

Support Ukraine
  • 42,271
  • 4
  • 38
  • 63