int m_strstr (const char*dst,const char*sub)
{
if (DST = = NULL | | sub = = NULL)
return NULL;
int d_length = strlen (DST) + 1;
int s_length = strlen (sub) + 1;
int dst_index;
int sub_index;
Int J;
for (dst_index = 0; Dst_index < d_length; ++dst_index)
{
Sub_index = 0;
if (dst[dst_index] = = Sub[sub_index])
{
j = Dst_index;
while (dst[j] = = Sub[sub_index])
{
++sub_index;
++j;
if (Sub_index = = (s_length-1))
return dst_index;
}
}
}
return-1;
}
char* m_strcpy (char* DST, const char* SRC)
{
if (DST = = NULL | | src = = NULL)
return NULL;
char* dst_t = DST;
while (*dst_t++ = *src++);
return DST;
}
void* m_memmove (void* dst,const void* src,int count)
{
if (DST = = NULL | | src = = NULL)
return NULL;
char* dst_t = (char*) DST;
char* src_t = (char*) src;
int s_length = strlen (src_t) + 1;
if ((int) DST < (int) src | | (int) DST > (int) src + s_length)
{
while (count--)
{
*dst_t++ = *src_t++;
}
}
Else
{
while (count)
{
* (dst_t + count) = * (src_t + count);
count--;
}
}
return DST;
}
int m_strcmp (const char* DST, const char* SRC)
{
assert (DST = = NULL);
ASSERT (src = = NULL);
while (*dst++ = = *src++) && (*dst! = ') && (*src! = '));
return *DST-*src;
}
This article is from the "end-of-the-guest" blog, please be sure to keep this source http://zheng2048.blog.51cto.com/10612048/1790773
C-language STR partial function implementation