I am working on the Blur filter in pset4 and I have received some very unusual errors when trying to compile my program.
The following is my code for the blur filter. As part of this, I have decided to write a function called blurAverage which takes in a couple of arguments, namely the value of int i and j from the forloop. Also, it takes a specific pixel within the 2d array of pixels called images. Lastly, it also takes in the int values for height and width which are defined in the filter.c cs50 provided code.
//Function definition prototype for blurAverage used in the blur function
void blurAverage(height, width, i, j, image[height][width], image[i][j]);
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
blurAverage(height, width, i, j, image[height][width], image[i][j])
}
}
return;
}
void blurAverage(height, width, i, j, image[height][width], image[i][j])
{
RGBTRIPLE temp;
int div = 0;
for (int x = 0; x < 2; x++)
{
for (int y = 0; y < 2; y++)
{
if(i + x - 1> 0 && j + y - 1> 0)
{
temp.rgbtBlue+= image[x][y].rgbtBlue;
temp.rgbtGreen+= image[x][y].rgbtGreen;
temp.rgbtRed+= image[x][y].rgbtRed;
div++;
}
}
}
image[i][j].rgbtBlue = temp.rgbtBlue/div;
image[i][j].rgbtGreen = temp.rgbtGreen/div;
image[i][j].rgbtRed = temp.rgbtRed/div;
}
I got 9 errors when I compiled this code, and they are follows:
I have 6 of the following types of errors:
helpers.c:162:43: error: subscripted value is not an array, pointer, or vector
temp.rgbtRed+= image[x][y].rgbtRed;
~~~~~^~
helpers.c:170:10: error: subscripted value is not an array, pointer, or vector
image[i][j].rgbtRed = temp.rgbtRed/div;
~~~~~^~
I am not sure if I follow this error above. In the shorts and in the lecture, we were told that arrays are pointers and that if you wanted the value of a specific pointer, you should simply use the [] syntax to target which specific element you needed. I was expecting that image[x][y].rgbtRed
would give me the value of value of the red color in the pixel image[x][y]
and then I was planning on storing it in temp.rgbtRed
. Given this understanding, I am not sure if I understand what the compiler is trying to tell me here. I even tried casting image[x][y].rgbtRed
as an int by using the following syntax (int) image[x][y].rgbtRed
I have 2 of the following types of errors which are dealing with potential issues with parenthesis placements.
void blurAverage(height, width, i, j, image[height][width], image[i][j]);
^
helpers.c:8:17: note: to match this '('
void blurAverage(height, width, i, j, image[height][width], image[i][j]);
^
helpers.c:8:18: error: a parameter list without types is only allowed in a function definition
void blurAverage(height, width, i, j, image[height][width], image[i][j]);
^
helpers.c:149:44: error: expected ')'
void blurAverage(height, width, i, j, image[height][width], image[i][j])
^
helpers.c:149:17: note: to match this '('
void blurAverage(height, width, i, j, image[height][width], image[i][j])
^
This one is a little unusual for me as well. I am not sure why it would ask me to put a close parenthesis right after the word image in image[height][width]
. Like its signalling me to the open parenthesis which I put at the start of the function declaration. Basically its asking me to put the function prototype and the declaration as follows:
void blurAverage(height, width, i, j, image**)**height][width], image[i][j]);
instead of how it is currently stated. Can someone please guide me here as to what I am doing wrong?
The last error was the most uncommon one to be honest. Like I am sure I am not doing anything wrong here.
helpers.c:8:18: error: a parameter list without types is only allowed in a function definition
void blurAverage(height, width, i, j, image[height][width], image[i][j]);
^
I am using various int's which have already been defined in this function prototype definition without actually stating their type. So like height, width, i, j are all integers but since this is a function definition and that these integers have been initialized elsewhere in the code, I am simply stating the name of the parameters without typing its type since that wouldn't be correct from my understanding. Based on the error message above, it seems as though the compiler doesn't recognize that this function prototype is indeed a prototype but I am using the correct syntax from what was taught in class. Can anyone guide me here?
Thank you.