im using codegear 2009 rad c++ builder and i cand think how to dynamically allocate memory to an array i tried using this code:
- Code: Select all
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "masyvai.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int *a; //dynamic array
int n; //variable for the dynamic array
n =StrToInt(Edit1->Text);
a = new int[n];
for(int i=1;i<n;i++)
{
a[i] = StrToInt(Edit2->Text[i]);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit2MouseEnter(TObject *Sender)
{
Edit2->Text = "";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1MouseEnter(TObject *Sender)
{
Edit1->Text = "";
}
//--
No luck everything runs but doesnt allocate memory coretly any ideas?

but thanks for the help