Thanks everyone. @Lundin , your advice is taken. I subsequently realised the check for '\0' should happen after the for loop terminates. So the modified code is
char * strstrci (char *s, char *p)
{
int i, j;
for (i = 0; s[i] != '\0'; i++)
{
if (s[i] == *p || s[i] == *p + 32 || s[i] == *p - 32)
{
for (j = 1; (s[i + j] == p[j] || s[i + j] == p[j] + 32 || s[i + j] == p[j] - 32) && p[j] != '\0'; j++);
if (p[j] == '\0')
return &s[i];
}
}
return NULL;
}
This seems to work for all cases.