您的位置:首页 > 其它

字符串查找strstr个人实现

2010-08-19 11:58 176 查看
=========================strstr个人实现=============================

char *Strstr(char *strSrc, const char *strDes)
{
int i, j;
int lenSrc = 0, lenDes = 0;
const char *pSrc = strSrc,
*pDes = strDes;
if ( strSrc == NULL || strDes == NULL )
return NULL;
while ( *pSrc++ )
lenSrc++;
while ( *pDes++ )
lenDes++;
i = j = 0;
while ( i < lenSrc && j < lenDes )
{
if ( strSrc[ i ] == strDes[ j ] )
{
i++;
j++;
}
else
{
i = i - j + 1;
j = 0;
}
}
if ( j >= lenDes )
return &strSrc[ i - j ];
return NULL;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: