头文件:
#include <string.h>
1、safe_strncpy函数
头文件:
#include <string.h>1、safe_strncpy函数
函数实现:
/* Like strncpy but make sure the resulting string is always 0 terminated. */
char * safe_strncpy(char *dst, const char *src, size_t size)
{
if (!size) return dst;
dst[--size] = '\0';
return strncpy(dst, src, size);
}
2、strncpy函数
函数实现
char* strncpy(char *dest, const char *src, size_t n){
size_t i;
for (i = 0 ; i < n && src[i] != '\0' ; i++)
dest[i] = src[i];
for ( ; i < n ; i++)
dest[i] = '\0';
return dest;
}
602

被折叠的 条评论
为什么被折叠?



