Implementation of "C language" strcpy function

Source: Internet
Author: User

The basic contents of the strcpy function:

Prototype declaration: extern Char *strcpy (char* dest, const char *SRC);

header files: #include <string.h> and #include <stdio.h>function: Copies a string that starts from the SRC address and contains a null terminator to Dest.address SpaceDescription: The memory areas referred to by SRC and dest cannot overlap and dest must have sufficient space to accommodate the SRC string. returns a pointer to the DestPointers. knowing the contents of the function, we can then 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!= ') {*str1++ = *str2++;} return TMP;} int main () {char p[10]= "abc"; char *q= "DEFG";p rintf ("%s\n", my_strcpy (P,q)); return 0;}
The results of the operation are as follows:

Implementation of "C language" strcpy function

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.