C language simulation to realize strcpy function

analyze

strcpy string copy,
write picture description here

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
char * my_strcpy( char* str1,const char* str2)
{
    char *ret = str1;
    assert(str1!=NULL);
    assert(str2!=NULL);
    while(*str1++ = *str2++)//将str1的内容复制到str1
    {
        ;
    }
    return ret;

}

test section

int main()
{
    char arr1[10]="hello ";
    char arr2[]="world";
    my_strcpy(arr1,arr2);
    printf("%s",arr1);
    system("pause");
    return 0;

}

operation result
write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325757811&siteId=291194637