c语言库函数【string.h】之strncpy_(char* dst,const char* src,int count)
代码如下:
#include<assert.h>
#include<stdio.h>
//strncpy函数,末尾不添加'/0'
char *strncpy_(char* dst,const char* src,int count)
{
char *start = dst; //首地址
while (count && (*dst++ = *src++)) /* copy string */
count--;
while(count--)
*dst++='/0';
return(start);
}
//strncpy函数,末尾添加'/0'
char * strncpyl_(char* dst,const char* src,int count)
{
char *start = dst; //首地址
while (count && (*dst++ = *src++)) /* copy string */
count--;
*dst = '/0';
return(start);
}