I am currently working on the pset4 , specifically the filter functions. I keep getting the error that -1 is out of bound of the array, but i went over the code multiple times and use debug50 to trace the different variable that i am using in the function can't seem to figure where the bug is or the problem with my logic.

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

int l = width - 1;

int m = round((float) width  / 2);

for(int i = 0; i < height; i++)

for(int j = 0; j < m; j++, l--)

      RGBTRIPLE temp = image[i][j];
      image[i][j] = image[i][l];
      image[i][l] = temp;

Errors Message:runtime error: index -1 out of bounds for type 'RGBTRIPLE [width]'


Reset l per line, like for example declaring it for the inner loop

for(int j = 0, l = width - 1; j < m; j++, l--)

I prefer this

for(int j = 0, l = width - 1; j < l; j++, l--)

with no need for an m.

  • You have helped me through other problem sets before, i just wanted to say thank you for taking the time to read through the questions and for helping out. This is great!! – mo_coder Jan 23 '20 at 14:18

You must log in to answer this question.

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