July 31st, 2003, 06:16 AM
-
good_strstr()
Is there any way to make this function case-insensitive ?
int good_strstr (char *str, char *key)
{
int cx, cl=0;
for (cx=0;cx<strlen(str);cx++)
{
if (str[cx]==key[cl])
{
cl++;
if (cl==strlen(key))
return 1;
continue;
}
cl=0;
}
return 0;
}
It searches for a key in string, if it founds - returns 1, else 0.
Thanks.
July 31st, 2003, 07:08 AM
-
I wrote this...
You should be able to modify this to suite your needs (no warrantee expressed or implied!)...
Code:
/********************************
*
*
* strncmpIC, like <string.h>'s strncmp, but case free
* and returns 1 if a match is made, zero otherwise (opposite of strncmp)
*
*******************************/
int strncmpIC(char * strA, char * strB, int maxlen){
int i=0;
while (strA[i] != '\0' && strB[i] != '\0' && i < maxlen){
if (toupper(strA[i]) != toupper(strB[i]))
break;
i++;
}
if (i == maxlen)
return 1;
else
return 0;
}
July 31st, 2003, 07:36 AM
-
yea, its good idea to use toupper()
thanks