String

當使用strncpy來複製字串時, 需注意strncpy並不處理字串結尾\0
所以需要先將該buf清空或在最後加\0
Example:
memset( buf,0,sizeof(buf));
strncpy( buf, string, sizeof(buf)-1);
or
strncpy( buf, string, sizeof(buf)-1);
buf[ sizeof(buf)-1 ] = '\0';
String

當使用strncpy來複製字串時, 需注意strncpy並不處理字串結尾\0
所以需要先將該buf清空或在最後加\0
Example:
memset( buf,0,sizeof(buf));
strncpy( buf, string, sizeof(buf)-1);
or
strncpy( buf, string, sizeof(buf)-1);
buf[ sizeof(buf)-1 ] = '\0';
:.: I am very thankful to this topic because it really gives up to date information -;*