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.
You’re writing past the end of
xandy, which is undefined behaviour. You need to make sure they’re large enough forrichTextBox1->Lines->Lengthelements.