>1. How can I search for a word in a string non-Case senstive... (using this code)
Well instead of using strstr you will have to use a function that does not depend on case. I have one here available from the merlin functions. It is called mstrstr and can be used just like strstr.
Code:
char* mstrstr(char *s1, const char *s2)
{
size_t i, value;
char *p;
char *s1b, *s2b;
if (strlen(s1)<strlen(s2))
return NULL;
if (*s1=='\0' || *s2=='\0')
return NULL;
s1b=malloc(strlen(s1)+1);
s2b=malloc(strlen(s2)+1);
if(s1b==NULL || s2b==NULL)
{
free(s1b);
free(s2b);
return NULL;
}
strcpy(s1b, s1);
strcpy(s2b, s2);
for(i=0; (s1b[i]=tolower(s1b[i]))!=0; i++)
;
for(i=0; (s2b[i]=tolower(s2b[i]))!=0; ++i)
;
p=strstr(s1b, s2b);
if(p==0)
{
free(s1b);
free(s2b);
return NULL;
}
else
{
value=p-s1b;
free(s1b);
free(s2b);
return &s1[value];
}
}
- Sean