strncpy的用法

char*strncpy(char*dest,char*src, size_tnum );

功能:




(c/c++)复制src中的

内容(字符,数字、汉字....)到dest,复制多少由num的值决定,返回指向dest的指针。如果遇到null字符(''),且还没有到num个字符时,就用(num - n)(n是遇到null字符前已经有的非null字符个数)个null字符附加到destination。注意:并不是添加到destination的最后,而是紧跟着由source中复制而来的字符后面。下面举例说明[1]:

chardes[] = "Hello,i am!";
charsource[] = "abcdef";
strncpy(des,source,5);
此时,des区域是这样的:a,b,c,,,逗号,i,空格,a,m,!
注意:,并不是添加在!的后面。
原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410824.html