Basic interview knowledge points (2)

Source: Internet
Author: User

The implementation of strcp strlcp memcp has been written again, and I do not know how many times it is. The size of the target string, string overlapping, wide characters, and four-byte optimization are not taken into consideration.

 

Char * strcp (char * DEST, const char * SRC) {assert (DEST! = NULL); Assert (SRC! = NULL); If (DEST = NULL | src = NULL) return NULL; char * save = DEST; while (* DEST ++ = * SRC ++ )! = '\ 0') {} return save;} size_t strlcp (char * DEST, const char * SRC, size_t size) {assert (DEST! = NULL); Assert (SRC! = NULL); If (DEST = NULL | src = NULL | size = 0) return 0; size_t size_ret = 0; size_t n = size; while (* DEST ++ = * SRC ++ )! = '\ 0') {If (0 = -- N) break; size_ret ++;} dest --; * DEST =' \ 0'; return size_ret + 1 ;} void * memcpy (void * DEST, void * SRC, size_t N) {assert (null! = DEST); Assert (null! = SRC); If (null = DEST | null = SRC | 0 = N) return NULL; void * ret = DEST; char * dest_temp = (char *) deST; char * src_temp = (char *) SRC; while (n --) {* dest_temp ++ = * src_temp ++;} 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.