模拟实现strncpy

匿名 (未验证) 提交于 2019-12-03 00:19:01


#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <assert.h>





char * My_strncpy(char * dest, const char *src, size_t n)
{
assert(dest);
assert(src);


char *ret = dest;
while (n--)
{
*dest++ = *src++;
}
return ret;
}


int main()
{
char str1[20] = "123456789";
char str2[20] = "abcde";





printf("调用My_strncpy之前: str1: %s \n", str1_1);
My_strncpy(str1, str2, 5); //调用My_strncpy
printf("调用My_strncpy之后: str1: %s \n", str1);


system("pause");
return 0;
}
文章来源: 模拟实现strncpy
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!