#include <stdio.h>
#include <string.h>
bool compare( char *src, char *dst, size_t n);
bool my_strstr( char *string, char *strCharSet )
{
int string_length = strlen(string);
int strCharSet_length = strlen(strCharSet);
int i , j;
i = j = 0;
char *temp;
for ( ; *string != '\0' ; )
{
if ( *string == *strCharSet )
{
temp = string;
return compare( temp, string, strCharSet_length -1 ) ;
}
else
string++;
}
return false;
}
void main( void )
{
char *str1 = "1234";
char *str2 = "56";
bool result = my_strstr( str1, str2 );
}
/********************************************************************
purpose: 对比两个字符串,在开始的n个字节中,是否相同。
相同的话返回true,不同返回false.
*********************************************************************/
bool compare( char *src, char *dst, size_t n)
{
size_t j = 0;
for ( size_t i = 0; i < n; ++i )
{
if ( src[i] == dst[i] )
j++;
else
break;
}
if ( j == n )
return true;
else
return false;
}