模拟实现strcpy

    xiaoxiao2022-07-07  146

    #include <stdio.h> #include <stdlib.h> char* my_strcpy(char* str1, const char* str2){ char* tmp = str1; //创建一个指向str1的指针 while (*(str1++) = *(str2++)); //str2依次赋给str1 return tmp; //返回值为char* } int main(){ char str1[20] = "ABCDEF"; char str2[20] = "QWERTY"; my_strcpy(str1, str2); printf("%s\n", str1); system("pause"); return 0; }
    最新回复(0)