#include <iostream> #include <assert.h> using namespace std; char *strcpy_mf(char *dst,const char *src) { assert((dst != NULL)&&(src != NULL)); char *temp = dst; while(*src != '\0') { *dst++ = *src++; } *dst = '\0'; return temp; } void main() { char *s2 = "copy11";//正常 //char *s2;//运行错误 //char *s2 = "";//运行正确,输出空串 char *s1 = (char *)malloc(strlen(s2)+1); strcpy_mf(s1,s2); cout << s1 <<endl; }