|
From: <Mat...@Ve...> - 2005-04-04 20:21:22
|
<?xml version=3D"1.0" ?>
This code is too complicated.
Use an STL structure like vector, list, slist, map, or hashmap.
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of
A_B...@gm...
Sent: Monday, April 04, 2005 1:16 PM
To: dev...@li...
Subject: [Dev-C++] flexibla array
Hi,
I'm trying to create an flexible array.
I have a structure named roomDat.
At the 1st und 2nd call of addRoom() every thing seems to be OK, but the
second time the will no memory be reserved, because the ID is always 2 after
the 1st call...
[CODE]
extern roomDat* Raum;
int cSpiel::addRoom(){
/* TODO (AB#1#): neuen Raum erstellen, ID zur=FCckgeben */
int ID =3D 0;
if(!Raum){
Raum =3D (roomDat*)malloc(sizeof(roomDat));=20
Raum->Prev =3D NULL;
Raum->Next =3D NULL;
Raum->ID =3D ++ID;
sprintf(Raum->Name, lang[7], ID);
Raum->Mesh =3D NULL;
Raum->Node =3D NULL; =20
wnd_Anfang.addRoom(Raum->Name, Raum->ID);
}else{
roomDat* tmp =3D Raum;
roomDat* tmp2 =3D NULL;
while(tmp){
if(tmp->ID > ID) ID =3D tmp->ID;
tmp2 =3D tmp;
tmp =3D tmp->Next;
}
tmp =3D (roomDat*)malloc(sizeof(roomDat));=20
tmp->Prev =3D tmp2;
tmp->Next =3D NULL;
tmp->ID =3D ++ID;
sprintf(tmp->Name, lang[7], ID);
tmp->Mesh =3D NULL;
tmp->Node =3D NULL; =20
wnd_Anfang.addRoom(tmp->Name, tmp->ID);
}
return ID;
}
[/CODE]
What's wrong ???
___________________________________________________________________
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
|