#include "stdafx.h"
#include <iostream>
/***
*strstr.c - search for one string inside another
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* defines strstr() - search for one string inside another
*
*******************************************************************************/
char * __cdecl My_strstr (
const char * str1,
const char * str2
)
{
char *cp = (char *) str1;
char *s1, *s2;
if ( !*str2 )
return((char *)str1);
while (*cp)
{
s1 = cp;
s2 = (char *) str2;
while ( *s1 && *s2 && !(*s1-*s2) )
s1++, s2++;
if (!*s2)
return(cp);
cp++;
}
return(NULL);
}
int _tmain(int argc, _TCHAR* argv[])
{
char *src_str = "abcdefgh";
char *in_str = "def";
char *tmp_p = My_strstr(src_str,in_str);
if (tmp_p == NULL)
{
std::cout<<"not find "<<in_str<<std::endl;
}
else
std::cout<<"find it "<<tmp_p<<std::endl;
system("pause");
return 0;
}
strstr在vc runtime 里的实现以及测试代码
最新推荐文章于 2022-05-24 19:44:08 发布