cs50 pset4 / меньше отражает check50 не работает - PullRequest
0 голосов
/ 06 апреля 2020

Мой код компилируется и работает правильно, но когда я использую check50, он говорит, что ни одно из «требований» не выполнено.

:( 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..."

Код:

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;
}

Я просмотрел много других сообщений и не могу найти решение. Это может быть просто маленькая деталь, но я не могу ее найти. любая помощь очень ценится. Спасибо!

1 Ответ

1 голос
/ 06 апреля 2020

Предположим, j == 0, и вы выполните

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

Какие индексы элементов поменялись местами? Они законны?

...