Try this......
Code:
#include <stdio.h>

int stripos(char *haystack, char *needle)
{
char *ptr1, *ptr2, *ptr3;

if( haystack == NULL || needle == NULL)
return -1;

for (ptr1 = haystack; *ptr1; ptr1++)
{
for (ptr2 = ptr1, ptr3 = needle; *ptr3 && (*ptr2 == *ptr3); ptr2++, ptr3++);
if (!*ptr3)
return ptr1 - haystack + 1;
}
return -1;
}

int main()
{
char str1[] = "Hello world";
char str2[] = "lo world";
char str3[] = "Bye";
printf("location of str2 in str1 is %d\n", stripos(str1, str2));
printf("location of str3 in str1 is %d\n", stripos(str1, str3));
return 0;
}
This is case-sensitive checking... if case-insensitive required, this can be done by changing the (*ptr2 == *ptr3) condition in for loop with a function which compares characters in case-insensitive way.

Last edited by shabbir; 15May2008 at 17:12.. Reason: Code block