[C Language] Implementation of strcpy function, strcpy Function

Source: Internet
Author: User

[C Language] Implementation of strcpy function, strcpy Function

Basic Content of the strcpy function:

Prototype Declaration: extern char * strcpy (char * dest, const char * src );

Header file: # include <string. h> and # include <stdio. h> function: copy the string starting from the src address and containing the NULL terminator to the address space starting with dest. Description: the memory areas specified by src and dest cannot overlap and dest must have enough space to hold src strings. Returns the pointer to dest. Now that you know the function content, we can simply implement this function:
# Include <stdio. h> # include <assert. h> char * my_strcpy (char * str1, char const * str2) {char * tmp = str1; assert (str1); assert (str2); while (* str2! = '\ 0') {* str1 ++ = * str2 ++;} return tmp;} int main () {char p [10] = "abc "; char * q = "defg"; printf ("% s \ n", my_strcpy (p, q); return 0 ;}
The running result is as follows:

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.