#i
#include <iostream>
#include <string>
using namespace std;
char* str_copy(char* dest,const char* src);
int main()
{
char* src="this is a test";
cout<<strlen(src)<<endl;
//申请内存大小时,需要在源串的长度上加1,以存放\0
char* test=(char*)(malloc(strlen(src)+1));
cout<<sizeof(test)<<endl;
str_copy(test,src);
if(test!=NULL)
{
cout<<test<<endl;
}
else
{
cout<<"No Enters"<<endl;
}
free(test);
//for console test
char c;
cin>>c;
//end test
return 0;
};
char* str_copy(char* dest,const char* src)
{
if(dest==NULL)
{return NULL;}
if(src==NULL || *src=='\0')
{return NULL;}
char* testTemp=dest;
while((*testTemp++=*src++)!='\0');
return testTemp;
}