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));
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;
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));
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;
wnd_Anfang.addRoom(tmp->Name, tmp->ID);
}
return ID;
}
[/CODE]
What's wrong ???
|