标签:-- from tar const emc 越界 ons 大于 ati
char * strcpy(char *to, const char *from) { char *save = to; for (; (*to = *from) != ‘\0‘; ++from, ++to); return(save); }
char * strncpy ( char * destination, const char * source, size_t count ) { char *start = dest; while (count && (*dest++ = *source++)) count--; if (count) //如果count大于零 即count is greater than the length of sources,‘\0‘已写入,不够的字符数都填充\ while (--count) *dest++ = ‘\0‘; //继续写dest指向的字符 return(start); }
size_t strlcpy(char *dest, const char *src, size_t size) { size_t ret = strlen(src); if (size) { size_t len = (ret >= size) ? size - 1 : ret; //防止源字符串的越界问题 memcpy(dest, src, len); dest[len] = ‘\0‘; } return ret; }
char * strncpy ( char * destination, const char * source, size_t num )
标签:-- from tar const emc 越界 ons 大于 ati
原文地址:http://www.cnblogs.com/tsunami-lj/p/7149164.html