strncpy
------------------------------------------------------------------------------------------------------------------------------
strncpy的正确用法:
strncpy(dest, src, sizeof(dest)); //size一定要用sizeof(dest)或sizeof(dest)-1,不可误用sizeof(src)
dest[sizeof(dest)-1] = ‘\0'; //务必要把dest的最后一个字节手工设置为0, 因为strncpy仅在src的长度小于dest时,对剩余的字节填0.
(1) 当dest长度远大于src时,由于strncpy会对多余的每个字节填0,会有很大的性能损失。
(2) strncpy返回dest,因而无法知道拷贝了多少个字节。