Code:
#define OFFSET ('a' - 'A')
int value(int c)
{
if(c >= 'a' && c <= 'z')
return c - OFFSET;
return c;
}
/*
* While I am sure Professor X at your school has not gone over
* const I am still going to use them for my own sanity.
*/
int stripos(const char* haystack, const char* needle, int offset)
{
int pos, i, j;
for(pos = 0; offset-- && haystack[pos]; pos++)
;
if(!haystack[pos])
return -1;
do
{
for(i = pos, j = 0; value(haystack[i]) == value(needle[j]) && haystack[i] && needle[j]; i++, j++)
;
if(needle[j] == '\0')
return pos;
if(haystack[i] == '\0')
break;
} while(haystack[++pos]);
return -1;
}