编程问题char *strstrEx(char *pSrc, unsigned int SrcLength,const char* pFind)

来源:百度知道 编辑:UC知道 时间:2024/06/26 01:46:49
char *strstrEx(char *pSrc, unsigned int SrcLength,const char* pFind)
{
unsigned int length,loop,loop2;
char *p;
length = strlen(pFind);
if(SrcLength < length) return NULL;
p = NULL;
for(loop = 0 ; loop < SrcLength-length ; loop++)
{
for(loop2 = 0 ; loop2 < length ; loop2++)
{
if(pSrc[loop+loop2] != pFind[loop2]) break;
}
if(loop2 == length)
{
p = &pSrc[loop];
break;
}
}
return p;
}
这个函数是什么意识,最好能解释的详细些,好的话追加20分

在pSrc这个字符串中搜寻pFind这个字符串,返回搜索到的字符串起始地址
例如:
pSrc = "This is a sourch string...";
pFind = "is";

pResult = strstrEx( pSrc, strlen(pSrc), pFine);

那么,pResult = "is is a sourch string...";
注意:pResult并没有新开辟一块内存。