Implementation of 5 library functions (my_strcmp strcat strncat my_strlen my_strstr)

Source: Internet
Author: User

1.
int my_strcmp (const char * str1, char * str2)//MY_STRCMP library function implementation
{
int ret = 0;
while ((*str1 = = *str2) && *str1&&*str2)
{
str1++;
str2++;
while (!) ( *STR1&&*STR2))
return 1;

}
return-1;

}

2.

char * strcat (char *str1, const char *STR2)//strcat library function Implementation method
{
char *CP = str1;
while (*CP)
cp++;
while (*cp++ = *str2++)
;
return str1;
}

3.

Char *strncat (char *str1, const char *STR2, int n)//strncat library function Implementation method
{
char *CP = str1;
while (*CP)
cp++;
while (n--)
{
if (! ( *cp++ = *str2++))
return str1;
}

return str1;
}

4.
An implementation method of the//my_strlen library function of the int my_strlen (const char *STR1)
{
int count = 0;
while (*STR1)
{
count++;
str1++;
}
return count;
}
5.
char * MY_STRSTR (const char *STR1, const char *STR2)//MY_STRSTR library function Implementation method
{
char *CP = str1;
char *S1 = CP;
Char *s2=null;
while (*S1)
{
S1 = CP;
s2 = str2;
while (*s1 && *s2 &&!) ( *S1-*S2))
{

s1++;
s2++;
}
if (*s2 = = ' + ')
{
return CP;
}
cp++;

}

return NULL;
}

This article is from the "0-point Time" blog, please make sure to keep this source http://10741764.blog.51cto.com/10731764/1712378

Implementation of 5 library functions (my_strcmp strcat strncat my_strlen my_strstr)

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.