C/C++ 字串拷貝(複製)
C/C++ 字串拷貝(複製)
資料來源:https://mp.weixin.qq.com/s/lZ9SsObIMoncjs4ZoyLRlA
線上編譯:https://www.tutorialspoint.com/compile_c_online.php
Code:
#include <stdio.h>
char *sky_strcpy(char *dst, const char *str)
{
if (NULL == dst || NULL == str)
{
return NULL;
}
char *ret = dst;
while (*str != '\0')
{
*dst ++ = *str ++;
}
return ret;
}
int main()
{
char str_1[100] = "hello,world";
char str[100] ={0};
sky_strcpy(str,str_1);
printf("str_1:%s\n",str_1);
printf("str :%s\n",str);
return 0;
}