/*
自行编写Strcpy()函数
*/
#include <iostream>
#include <string.h>
using namespace std;
//-------------------------------------
char* Strcpy(char* dest,const char* src)
{
if(dest == NULL) return NULL;
if(src == NULL) return NULL;
while(*src != '\0')
{
*dest++ = *src++;
}
*dest = '\0'; //dest最后一个必须要有 '\0'
return dest;
}
int main(int argc, char *argv[])
{
const char* src = "abcdefghijklmnopqrstuvwxyz";
unsigned int length = strlen(src);
cout << length << endl;
//---------------------------------------------------
char str1[length+1]; //strlen测出来的不包括'\0' 这里不能用字符串指针,,因为不知道要分配多少
Strcpy(str1,src);
cout << str1 << endl;
//---------------------------------------------------
char* str2;
Strcpy(str2,src);
cout << str2 << endl;
//---------------------------------------------------
char* str3 = new char[length+1];
Strcpy(str3,src);
cout << str3 << endl;
delete []str3;
str3 = NULL;
return 0;
}