/*
*dest 要被检索的内存起始地址
DestSize 检索匹配大小
*str 要搜索的内存起始地址
StrSize 搜索的大小
*/
// 内存数据对比匹配
/* 要被检索的内存起始地址,检索匹配大小,要搜索的内存起始地址,搜索的大小*/
char * tm_strstr(const char *dest,unsigned int DestSize, const char *str,unsigned int StrSize)
{
char *ptr=NULL;
char *sr1 = (char*)dest;
char *sr2 = (char*)str;
unsigned int m1 = 0;
unsigned int m2 = 0;
if(dest==NULL || str==NULL || DestSize >StrSize)return NULL;
for(unsigned int i=0;i<StrSize;i++) //暴力查询
{
m1 = 0;m2 = 0;
ptr = &sr2[i]; //起始位置
while(m1 != DestSize && sr1[m1] == ptr[m2] && i+m2 <StrSize)
{
m1++;
m2++;
}
if(m1 == DestSize)return (char *)ptr; //对比成功
}
return NULL;
}