Konat Undoshy
Konat Undoshy

Reputation: 421

Problem with filling a two-dimensional array in c++

I'm trying to fill a two-dimensional array of int in c++.

But i have a weird problem. Basically right now i have a code like that :

int array[83][86];
int test_1 = 0;
int test_2 = 0;
for (int x = box.min_corner().x(); x < box.max_corner().x(); x = x + 50)
{
    for (int y = box.min_corner().y(); y < box.max_corner().y(); y = y + 50)
    {
        point_t point_p(x, y);
            if (bg::within(point_p, poly))
            {
                array[test_1][test_2] = '1';
            }
            else {
                array[test_1][test_2] = '0';
            }
            test_2++;
    }
    test_1++;
}

My program crashes before all columns are filled. Basically my program stop column 58. The problem is not my two for loops, because if I increase my array like this : int array[83 * 2][86]; It continues normally, as it is supposed to work initially.

Anyone have an idea of what can trigger this issue ?

Upvotes: 0

Views: 69

Answers (1)

Llu&#237;s Alemany-Puig
Llu&#237;s Alemany-Puig

Reputation: 1243

You have to reset test_2 to 0 appropriately. Otherwise, you keep incrementing the variable and it eventually goes past the limit of 86.

Upvotes: 3

Related Questions