Can anyone help me improve my instr()
function?
int myInstr(wchar_t *str, wchar_t c, int start, int dir){
int pos = 0, result = 0, len;
wchar_t *p1;
//Left
if(dir == 0)
{
p1 = str;
len = lstrlen(str);
while(pos < len)
{
if(*p1 == c)
{
result = pos;
return result;
}
p1++;
pos++;
}
}
else
{
//Right
pos = len = lstrlen(str);
p1 = str;
p1 += len;
while(pos >= 0)
{
if(*p1 == c)
{
result = pos;
return result;
}
p1--;
pos--;
}
}
return 0;
}