I'm currently working on the reflect function, I'm going to include my code below


What problem are you having? Describe the problem in detail. If appropriate, include any error messages, screenshots, or small snippets of code to describe the issue. (Keeping in mind the course's policy on academic honesty, do not share code that may contain spoilers or solutions.) So your are seeing my code above and it's compiling without error messages. But when im running it, I'm returning an unswapped image. Im hoping I have delt with the problem that I have been running over "too much" of the line, thus only iterating over half of it now and coding different algorithms for even and uneven lengths of arrays. So I'm sure it has something to to with the way I'm using the data. Since here, I'm just creating copies and do not change the actual data.What have you already tried so far to resolve the issue?I tried implementing my code in a similar fashion like we saw in the lecture:

RGBTRIPLE tmp = *image[i][j];
        *image[i][j] = *image[i][h];
        *image[i][h] = tmp;

But that returns the following errormessage if I compile the code:

error: indirection requires pointer operand ('RGBTRIPLE' invalid) RGBTRIPLE tmp = *image[i][j]; and for the other lines respectively. I'm doing something wrong here but I'm not sure what!


The * are meant to dereference a pointer. But image[i][j] is not a pointer, but a value. So remove the *.

As a bit of background, image is a pointer, but you already dereference it by applying i and j, as image[i][j] is equivalent to *(image + width * i + j).

Also, don't forget to decrement h the same time you increment j, you can do like ; j++, h--).

!width%2 == 0 is a bit confusing, as it means (!width) % 2 == 0 (which is true for any non-zero width). You probably meant width % 2 != 0.

BTW, you can use j < width / 2 for both. Dividing two integers is an integer again, rounding towards zero (ignoring the fractional part). Or, you could use j < h.


You don't need to put * It is a pointer.

You must log in to answer this question.

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