Notes on C language copy Functions

Source: Internet
Author: User

 

I need to use these functions in my work today. I have a little understanding of the differences between these functions and write a short article:

1. char * strcpy (char * DEST, char * SRC); this function copies the string ending with '\ 0' indicated by Src to the array indicated by DeST. The memory areas specified by Src and DEST cannot overlap and DEST must have enough space to hold SRC strings. When the SRC string length> DEST String Length,ProgramThe entire SRC string will still be copied to the Dest region, but the Dest array has exceeded.

2. char * strncpy (char * DEST, char * SRC, size_t, N ); copy up to n characters in the SRC string to the Dest character array (it does not stop copying when it encounters null like strcpy, but starts copying only when it has enough n characters ), returns the pointer to DeST.

3. Void * memcpy (void * DEST, const void * SRC, size_t N ); data of N consecutive bytes directed by Src to the starting address is copied to the space where the starting address is directed by DeST .. The source and DESTIN memory regions cannot overlap. The function returns a pointer to Destin. Compared with strcpy, memcpy does not end when '\ 0' is encountered, but will definitely copy n Bytes. If the target array DESTIN already has data, after memcpy () is executed, the original data will be overwritten (N at most ). If you want to append data, you need to add the target array address to the address where you want to append the data after executing memcpy.

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.