ANSI C 88实现的忽略大小写strstr函数,帮忙挑挑毛病
总是觉得太罗嗦,大家帮帮忙,给指点指点,有没有更好的思路?
char* strstrNoCap( const char *str1, const char *str2 )
{
int i = 0, j = 0;
char *rv = 0;
int ch1 = 0, ch2 = 0;
while(*(str1+i))
{
while(*(str2+j))
{
ch1 = (*(str1+i+j)>96) ? -32 : 0;
ch2 = (*(str2+j)>96) ? -32 : 0;
if((ch2 + *(str2+j)) == (ch1 + *(str1+i+j)) )
{
rv = str1 + i;
j++;
}
else
{
rv = 0;
break;
}
}
if(rv != 0)
return rv;
else
i++;
}
return rv;
}
char* strstrNoCap( const char *str1, const char *str2 )
{
int i = 0, j = 0;
char *rv = 0;
int ch1 = 0, ch2 = 0;
while(*(str1+i))
{
while(*(str2+j))
{
ch1 = (*(str1+i+j)>96) ? -32 : 0;
ch2 = (*(str2+j)>96) ? -32 : 0;
if((ch2 + *(str2+j)) == (ch1 + *(str1+i+j)) )
{
rv = str1 + i;
j++;
}
else
{
rv = 0;
break;
}
}
if(rv != 0)
return rv;
else
i++;
}
return rv;
}
...全文
相关推荐
C 语言中strstr函数实例详解
主要介绍了C 语言中strstr函数实例详解的相关资料,需要的朋友可以参考下
关于C语言函数strstr()的分析以及实现
原型:char *strstr(const char *str1, const char *str2);#include<string>找出str2字符串在str1字符串中第一次出现的位置(不包括str2的串结束符)。返回该位置的指针,如找不到,返回空指针。Returns a pointer to the first occurrence of strSearch in str, or NULL if strSearch does not appear in str. IfstrSearch points to a string of zero length, the function r
C++中strstr函数的实现方法总结
主要介绍了C++中strstr函数的实现方法总结的相关资料,希望通过本文能帮助到大家,让大家掌握这部分内容,需要的朋友可以参考下
strstr和strcpy函数实现
strstr函数和strcpy函数的简单实现
strstr,strdup,strsep 三函数实现
strstr,strdup,strsep 三函数实现


