#include <iostream>
using namespace std;
void MyStrcpy(char *strDes, const char *strSrc);
int main()
{
char *p = "abcde";
char *q = "";
char a[] = "abcde\0";
//cout << strlen(a);
//cout << a;
MyStrcpy(q, p);
std::cout << q << std::endl;
system("pause");
return 0;
}
void MyStrcpy(char *strDes, const char *strSrc)
{
size_t length = strlen(strSrc);
strDes = new char(length + 1);
for (int i = 0; i < length; i++)
{
strDes[i] = strSrc[i];
}
strDes[length] = '\0';
//return strDes;
}
我测试了这个是失败的赋值,这个是为什么呢?我觉得指针赋值是应该成功啊