I have a seg fault in C++ when entering a for loop. But I mean when ENTERING IT. Here is the code I'm running:
std::cout<<"forcing order"<<endl;
std::cout<<"crossoverPointNumber = "<<crossoverPointNumber<<endl;
for (long j=0; j<crossoverPointNumber; j++)
{
std::cout<<"j = "<<j<<". ";
offsprings[1][positionsInParent1[j]] = valuesInParent2[j]; // Forces the order
}//end for j
The output I get on the terminal is:
forcing order
crossoverPointNumber = 4
Segmentation fault
Can anyone explain to me what am I missing here?? it seems to be either very elementary or very complex C++ stuff...
offspringsoffsprings[1]intended? Do you want to access the first element? You'd have to writeoffsprings[0], since C arrays are zero-based.