|
From: Per W. <pw...@ia...> - 2005-04-04 20:51:11
|
See missing line below.
By the way, I don't very much like variable names 'tmp' and 'tmp2'.
How about calling them 'current' and 'previous' or something similar,
since they represent the order of the entries when iterating through the
list.
And by the way - this is a normal dual-linked (forward+backward) list, not
a flexible (?) array.
One more thing - why post a mail to a mailing list, claiming that the
contents of the mail is or may be proprietary? The only legalese that
might be suitable for mailing lists is that expressed oppinions are your
personal ones, and not necessarily the official ones of a
company/organisation/...
/Per W
On Mon, 4 Apr 2005 Mat...@Ve... wrote:
> <?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 af=
ter
> 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));
you are missing a
tmp2->Next =3D tmp;
to let the previous tail point to the new entry
> 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 ???
>
> ___________________________________________________________________
> 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.
>
>
|