Source code: Implementation source code of Microsoft strcpy, strcat and strcmp

Source: Internet
Author: User

 

/***

* Char * strcpy (DST, Src)-copy one string over another

*

* Purpose:

* Copies the string SRC into the spot specified

* DEST; assumes enough room.

*

* Entry:

* Char * DST-string over which "src" is to be copied

* Const char * Src-string to be copied over "DST"

*

* Exit:

* The address of "DST"

*

* Exceptions:

**************************************** ***************************************/

Char * strcpy (char * DST, const char * SRC)

{

Char * CP = DST;

While (* CP ++ = * SRC ++)

;/* Copy SRC over DST */

Return (DST );

}

/***

* Char * strcat (DST, Src)-concatenate (append) one string to another

*

* Purpose:

* Concatenates SRC onto the end of DeST. Assumes enough

* Space in DeST.

*

* Entry:

* Char * DST-string to which "src" is to be appended

* Const char * Src-string to be appended to the end of "DST"

*

* Exit:

* The address of "DST"

*

* Exceptions:

*

**************************************** ***************************************/

Char * strcat (char * DST, const char * SRC)

{

Char * CP = DST;

While (* CP)

CP ++;/* Find end of DST */

While (* CP ++ = * SRC ++);/* Copy SRC to end of DST */

Return (DST);/* return DST */

}

/***

* Strcmp-compare two strings, returning less than, equal to, or greater

*

* Purpose:

* Strcmp compares two strings and returns an integer

* To indicate whether the first is less than the second, the two are

* Equal, or whether the first is greater than the second.

*

* Comparison is done byte by byte on an unsigned basis, which is

* Say That null (0) is less than any other character (1-255 ).

*

* Entry:

* Const char * Src-string for left-hand side of comparison

* Const char * DST-string for right-hand side of comparison

*

* Exit:

* Returns-1 If SRC <DST

* Returns 0 if src = DST

* Returns + 1 If SRC> DST

*

* Exceptions:

*

**************************************** ***************************************/

Int strcmp (const char * SRC, const char * DST)

{

Int ret = 0;

While (! (Ret = * (unsigned char *) Src-* (unsigned char *) DST) & * DST)

++ SRC, ++ DST;

If (Ret <0)

Ret =-1;

Else if (Ret> 0)

Ret = 1;

Return (RET );

}

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.