my code works perfectly in visual studio yet i encounter a problem running it in eclipse. in the function:
City* Gps::FindCity(const char* city)
{
if(city != NULL)
{
City *tmp = NULL;
if (! m_gpsCities.empty())
{
for (list<City*>::iterator iter = m_gpsCities.begin(); iter != m_gpsCities.end(); iter++)
{
tmp = (City*)(*iter);
if(Vehicle::StringCompare(tmp->GetCityName(),city)==0)
return tmp;
}
}
}
return NULL;
}
the problem is, that after the first iteration, and while the list has more then 1 elements, it exits the loop, and doesn't go over the other elements in the list.
stringcompare:
int Vehicle::StringCompare(const char* str1, const char* str2)//assuming all not null
{
string s1, s2;
char *st1 = OrgName(str1),*st2 = OrgName(str2);
s1.assign(st1);
s2.assign(st2);
int size1 = s1.size(), size2 = s2.size(), min = 0, index =0;
if(str1[size1 - 1] == '\r' || str1[size1 - 1] == '\0' || str1[size1 - 1] == '\n')
size1--;
if(str2[size2 - 1] == '\r' || str2[size2 - 1] == '\0' || str2[size2 - 1] == '\n')
size2--;
if(size1>size2)
min=size2;
else
min=size1;
bool bigger1 = true;
for(index=0;index<min;index++)
{
if(st1[index]>st2[index])
return 1;
if(st1[index]<st2[index])
return (-1);
}
delete[] st1;
delete[] st2;
if(size1==size2)
return 0;
if(min==size1)
return (-1);
else
return 1;
}