BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TList

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Paulo Dias
Guest





PostPosted: Wed Mar 30, 2005 12:36 am    Post subject: TList Reply with quote



typedef struct mList
{
float motif[9];
}TmList;

typedef TmList* SmList;

TList *population = new TList();
SmList mStruct;

i make this declarations... then i use this code:

void __fastcall TBaseForm::GeneratePopulation(int nElements)
{
// delete elements in the list
for (int i=0; i<population->Count; i++)
{
mStruct=(SmList)population->Items[i];
delete mStruct;
}

// for each element of the population
for(int i=0; i<nElements; i++)
{
mStruct = new TmList;
<------------------------------------------------------------- After 2
iteration code explods in this line

// fill motif values
for(int j=0; j<10; j++)
mStruct->motif[j]= (float) rand()/RAND_MAX;

population->Add(mStruct);
}
}


please can someone help me...

Thanks in advance

Paulo Dias


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Mar 30, 2005 1:18 am    Post subject: Re: TList Reply with quote




"Paulo Dias" <dias.paulo (AT) gmail (DOT) com> wrote


Quote:
// delete elements in the list
for (int i=0; i<population->Count; i++)
{
mStruct=(SmList)population->Items[i];
delete mStruct;
}

You are not clearing the TList. You are adding new items to the existing
list without removing the now-invalid items that you just deleted.


Gambit



Back to top
Wiljo
Guest





PostPosted: Wed Mar 30, 2005 11:31 am    Post subject: Re: TList Reply with quote



Paulo Dias wrote:
Quote:
typedef struct mList
{
float motif[9];
}TmList;

...
------------------- After 2 iteration code explods in this line

// fill motif values
for(int j=0; j<10; j++)
mStruct->motif[j]= (float) rand()/RAND_MAX;

population->Add(mStruct);
}
}


please can someone help me...

Thanks in advance

Paulo Dias



Well, what I see here is that your motif float array contains 9 elements from 0
upto and including 8. You are iterating it with j from 0 upto and including 9
(j<10), thus you are accessing the motif array outside it's range.

Either enlarge the array to 10, because you are iterating 10 elements, or
decrease the limit of the loop.

float motif[ 9 ];

This line means that an array of 9 elements is reserved, but because arrays
start at index 0 the index of their last element is total number of elements
minus one. In this case the range is from 0 upto 8.

Wiljo.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.