i’m having a problem using stricmp in a specific function, in other functions it works perfectly, except this one.
the problem is that even if it compares the same string (char*) it doesn’t return 0.
what might be the problem?
(sorry for the mess, i’ll try formatting it)
that’s the code:
Employee* CityCouncil::FindEmp(list<Employee*> *lst, char* id)
{
bool continue1 = true;
Employee* tmp= NULL;
char* tmpId = NULL, *tmpId2 = NULL;
list<Employee*>::iterator iter = lst->begin();
if ((id == NULL) || (lst->empty()==true))
return NULL;
while ((iter != lst->end()) && (continue1)){
tmp = (Employee*)(*iter);
tmpId = (*tmp).GetId();
if(tmpId != NULL)
{
if(stricmp(tmpId,id) == 0)
continue1 = false;
}
if (continue1 == true)
iter++;
}
if (iter == lst->end())
return NULL;
return (Employee*)(*iter);
}
Never blame a function that belongs to the C library. stricmp surely works as expected, meaning the strings are really different. There must be something wrong with the logic in this function – you should use
printfstatements to find out where and why the strings differ.EDIT: I put together a simple test program. This works for me:
Note that I used the function you provided. Again, there is nothing wrong with stricmp, the problem must be in your code.