Rewrite the string operator function in string. H-strncat

Source: Internet
Author: User

Function prototype: char * strncat (char * DEST, const char * Source, size_t size)

Return Value: returns the pointer to the first address of the target string DeST. If null is returned, an error occurs.

Parameter description:

DeST: string with '/0' as the Terminator

Source: string with '/0' as the ending character

Size: number of characters to connect to the end of the dest

Function: connects the size starting from source to the end of DeST and overwrites '/0' to connect strings.

Implementation:

 

Char * strncat (char * DEST, const char * Source, size_t size)

{
Assert (null! = DEST) & (null! = Source ));
Char * TMP = DEST;
If (size)
{
While (* DEST)
DeST ++;
While (* DEST ++ = * Source ++ ))
{If (-- size = 0)
Break;
}
}
Return TMP;
}

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.