字符串查找算法

来源:互联网 发布:淘宝0元购是真的吗 编辑:程序博客网 时间:2024/06/11 09:51
const char* mstrstr(const char* srcstr,const char*findstr)
{
int index = 0;
assert((index = strlen(findstr) - 1) <=(strlen(srcstr) - 1));

    int i,j;
for(i = 0,j = index;srcstr[i] != 0;)
{
if(findstr[j] == srcstr[i + j])
{
if(j == 0)
{
return &srcstr[i + j];
}
--j;
}
else
{
for(;findstr[j] != srcstr[i + j];++i)
{
if(srcstr[i + j] == 0)
return NULL;
}
j = index;
}
}
return NULL;
}
0 0