char *strcpy(char *restict dst,const char *restrict src);dst是目的,src是原
这会把src的字符串拷贝到dst
restrict表示src和dst不重叠
返回dst
char *dst=(char*)malloc(strlen(src)+1);
strcpy(dst,src);
#include <stdio.h>
#include <string.h>
char* mycpy(char* dst,const char* src)
{
//int idx = 0;
//while(src[idx]){
//dst[idx]=src[idx];
//idx++;
//}
//dst[idx] = '\0';
char*ret = dst;
while(*src !='\0'){
*dst = *src;
dst++;
src++;
}
*dst ='\0';
return ret;
}
int main(int argc,char const *argv[])
{
char s1[] = "abc";
char s2[] = "abc";
mycpy(s1,s2);
printf("%d %d",s1,s2);
return 0;
}