#include <stdio.h>
#include <string.h>
char *myStrnCpy(char *dest,char *src,int count)
{
char *tmp = dest;
while(count--)
{
if(*src != '\0')
{
*dest++ = *src++;
}
else
{
*dest++ = '\0';
}
}
return tmp;
}
int main()
{
char dest[1024]={"123"};
char *src = "srcabc";
//myStrnCpy(dest,src,10);
printf("dest = %s\n",myStrnCpy(dest,src,2));
return 0;
}
笔试题 -- strncpy实现
最新推荐文章于 2024-08-16 21:54:14 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)