I believe I've done this part of filter-more task pretty well, but, unfortunately, an output image has some artifacts - blur works badly with white parts of an image.
void blur(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE *grid[3][3];
long averageB, averageG, averageR;
// Checks If grid's pixels exist
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
int n = 1;
if(y - 1 >= 0 && x - 1 >= 0)
{
n++;
grid[0][0] = &image[y - 1][x - 1];
}
else
grid[0][0] = NULL;
if(y - 1 >= 0)
{
n++;
grid[0][1] = &image[y - 1][x];
}
else
grid[0][1] = NULL;
if(y - 1 >= 0 && x + 1 <= width - 1)
{
n++;
grid[0][2] = &image[y - 1][x + 1];
}
else
grid[0][2] = NULL;
if(x - 1 >= 0)
{
n++;
grid[1][0] = &image[y][x-1];
}
else
grid[1][0] = NULL;
grid[1][1] = &image[y][x];
if(x + 1 <= width - 1)
{
n++;
grid[1][2] = &image[y][x + 1];
}
else
grid[1][2] = NULL;
if(y + 1 <= height - 1 && x - 1 >= 0)
{
n++;
grid[2][0] = &image[y + 1][x - 1];
}
else
grid[2][0] = NULL;
if(y + 1 <= height - 1)
{
n++;
grid[2][1] = &image[y + 1][x];
}
else
grid[2][1] = NULL;
if(y + 1 <= height - 1 && x + 1 <= width - 1)
{
n++;
grid[2][2] = &image[y + 1][x + 1];
}
else
grid[2][2] = NULL;
// Cacluclate an average for every colour
for(int a = 0; a < 3; a++)
{
for(int b = 0; b < 3; b++)
{
if(grid[a][b] != NULL)
{
averageB += (*grid[a][b]).rgbtBlue;
averageG += (*grid[a][b]).rgbtGreen;
averageR += (*grid[a][b]).rgbtRed;
}
}
}
averageB = averageB / n;
averageG = averageG / n;
averageR = averageR / n;
grid[1][1]->rgbtBlue = averageB;
grid[1][1]->rgbtGreen = averageG;
grid[1][1]->rgbtRed = averageR;
}
}
return;
}