C-language STR partial function implementation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.