0

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 ?

3
  • what is box.min_corner() and box.max_corner() ? Commented Jan 17, 2022 at 14:59
  • 2
    I prefer the terminology "two-dimensional array" or "2D array" to "double array". Commented Jan 17, 2022 at 15:02
  • @Wyck in my vocabulary, “double array” is std::array<double, N>, or possibly loosely defined as any contiguous storage of double. I avoid C-style “arrays”. Commented Jan 17, 2022 at 15:08

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.