自己写个函数,
设置一个数组,数组长度为字符串T的长度,将其读取至数组中,然后再复制至S就可以了
自己仿造strcpy写一个就可以了
char* my_strcpy(char *t, char *s)
{
if(!s)
return NULL;
char *p = s;
while(*p)
{
*t = *p;
p++;
t++;
}
t = '\0';
return s;
}
char * copy(char *s,char *t){
char * tmp=s;
while(*tmp!='\0'){
*tmp=*t;
tmp++;
t++;
}
*tmp='\0';
return s;
}
char *strcpy(char *s, const char *t)
{
char *address = s;
if((NULL == s)||(NULL == t))
return NULL;
while(*s++ = *t++);
return address;
}
string str1= "aaa";
string str2= "bbb";
str2=str1;