Probado y funcionando en c++builder:
const int nArticulos = 4;
char *articulos[nArticulos][2] = {{"pescado", "2,22"},
{"carne", "3,33"},
{"fruta", "1,50"},
{"hortalizas", "0.50"}
};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
for(int i = 0; i < nArticulos; i++)
ListBox1->Items->Add(*articulos[i]);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1Click(TObject *Sender)
{
Extended precio;
try {
precio = StrToFloat(articulos[ListBox1->ItemIndex][1]);
Edit1->Text = FormatFloat("0.000", precio) + "$";
}
catch(const Exception &)
{
Edit1->Text = "Error";
ShowMessage("El precio para este articulo no tiene el formato apropiado.");
}
}
//---------------------------------------------------------------------------