Program that adds points to a chart exits with code 0xc0000409

1

I wrote a function that adds lines from a richTextbox into a array and than adds them to the chart.

        double y[] = { 0 };
        double x[] = { 0 };

        String^ name = "Pobrana moc";
        chart1->Series->Clear();
        chart1->Series->Add(name);

        for (int i=0; i < richTextBox1->Lines->Length; i++){ 
            y[i] = Convert::ToDouble(richTextBox1->Lines[i]);
            x[i] = i+1;
            chart1->Series[name]->Points->AddXY( x[i] , y[i] );
        }

I compile the program with no problems detected. When I run it and call this function the program closes with this message: The program '[6356] GUI.exe: Managed (v4.0.30319)' has exited with code -1073740791 (0xc0000409).

If I replace all "i" with a number it works perfectly well:

            y[0] = Convert::ToDouble(richTextBox1->Lines[0]);
            x[0] = 1;
            chart1->Series[name]->Points->AddXY( x[0] , y[0] );

What have I done wrong, or is there any other way to make it work? I need it to add as many points to the chart as there are lines in the richTextbox.

c++
arrays
visual-studio-2010
charts
asked on Stack Overflow Feb 1, 2013 by illid44n • edited Sep 5, 2013 by DisplayName

1 Answer

1

You're writing past the end of x and y, which is undefined behaviour. You need to make sure they're large enough for richTextBox1->Lines->Length elements.

answered on Stack Overflow Feb 1, 2013 by NPE

User contributions licensed under CC BY-SA 3.0