简体   繁体   中英

cs50 pset4/less reflect check50 not working

My code compiles and runs properly but when I use check50 it says none of the 'requirements' are met.

:( reflect correctly filters 1x2 image
    expected "0 0 255\n255 0...", not "3 0 0\n0 0 255..."
:( reflect correctly filters 1x3 image
    expected "0 0 255\n0 255...", not "246 55 65\n0 2..."
:( reflect correctly filters image that is its own mirror image
    expected "255 0 0\n255 0...", not "0 255 0\n255 0..."
:( reflect correctly filters 3x3 image
    expected "70 80 90\n40 5...", not "110 130 140\n4..."
:( reflect correctly filters 4x4 image
    expected "100 110 120\n7...", not "110 130 140\n1..."

Code:

void reflect(int height, int width, RGBTRIPLE image[height][width])
{
    void swap (RGBTRIPLE*, RGBTRIPLE*);
    for (int i = 0; i < height; i++)
    {
        int n = 1;
        for (int j = 0; j < width / 2; j++)
        {
            swap (&image[i][j], &image[i][(width - j)]);
            n++;
        }
    }
     return;
}
void swap (RGBTRIPLE*a, RGBTRIPLE*b)
 {
    RGBTRIPLE tempArray;
    RGBTRIPLE tempArray2;
    tempArray = *a;
    tempArray2 = *b;
    *a = tempArray2;
    *b = tempArray;
}

I've looked through many other posts and I cant find any solution. It might just be some small detail bu I can't find it. any help is greatly appreciated. Thanks!

Suppose j == 0 and you execute

swap (&image[i][j], &image[i][(width - j)]);

What are the indices of the elements swapped? Are they legal?

It might be something as simple as your swap function call. The second argument of swap might work better if it was

swap (&image[i][j], &image[i][width-1-j])

That won't make much of a difference to the eye, but it might make a big difference to the Cs50 check program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM