#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> #include<assert.h> char *my_strcpy(char *dest, char *src) { assert(dest); assert(src); char *ret = dest; while ((*dest++ = *src++) )//連同‘\0’一起拷貝了 { ; } /*while (*src) { *dest = *src; dest++; src++; }*/ //原串為‘\0’時跳出,並未拷貝‘\0’,要賦值*dest = '\0' *dest = '\0'; return ret; //自加有副作用,因此return dest 可能讀到最後'\0'就不輸出了 }