Hello
I want to solve it randomly reads the lines.
I found a source code, but it will crash the program.
This is source code:
DWORD cFindEvent::GetRandomPosition()
{
//---------------------------------------------------------------------------------------
FILE * garew = fopen (MobCoords,"r");
//---------------------------------------------------------------------------------------
char temp[1024];
int i = 0;
int j = 0;
int licz = rand() % 100;
//---------------------------------------------------------------------------------------
while ( !feof(garew) && i <= licz)
{
//-----------------------------------------------------------------------------------
fgets(temp , 1024 , garew );
//-----------------------------------------------------------------------------------
if(temp[0] != '/' && temp[1] != '/')
{
//-------------------------------------------------------------------------------
sscanf(temp,"%d %d %d", &DayMap, &DayX, &DayY);
if(DayMap >= 0)
{
//---------------------------------------------------------------------------
i++;
//---------------------------------------------------------------------------
}
//-------------------------------------------------------------------------------
}
//-----------------------------------------------------------------------------------
}
//---------------------------------------------------------------------------------------
fclose(garew);
//---------------------------------------------------------------------------------------
FILE * garew2 = fopen (MobCoords,"r");
//---------------------------------------------------------------------------------------
if(licz > i)
{
//-----------------------------------------------------------------------------------
int licz2 = rand() % i;
//-----------------------------------------------------------------------------------
while ( j <= licz2 )
{
//-------------------------------------------------------------------------------
fgets(temp , 1024 , garew2 );
//-------------------------------------------------------------------------------
if(temp[0] != '/' && temp[1] != '/')
{
//---------------------------------------------------------------------------
sscanf(temp,"%d %d %d", &DayMap, &DayX, &DayY);
if(DayMap >= 0)
{
//-----------------------------------------------------------------------
j++;
//-----------------------------------------------------------------------
}
//---------------------------------------------------------------------------
}
//-------------------------------------------------------------------------------
}
//-----------------------------------------------------------------------------------
}
//---------------------------------------------------------------------------------------
fclose(garew2);
//---------------------------------------------------------------------------------------
DWORD Reward = DNState.DayBossIndex=CreateMobInXY(21,DayMap,DayX,DayY);
Chat.MessageAll(0,0,NULL,"The monster entered the coordinates: %d x %d", DayX, DayY);;
//---------------------------------------------------------------------------------------
return Reward;
//---------------------------------------------------------------------------------------
}
Txt file content:
0 63 120
0 63 125
0 70 140
What's wrong with this?