軟體開發, 理財投資與生活543
當使用strncpy來複製字串時, 需注意strncpy並不處理字串結尾\0所以需要先將該buf清空或在最後加\0
Example:memset( buf,0,sizeof(buf));strncpy( buf, string, sizeof(buf)-1);orstrncpy( buf, string, sizeof(buf)-1);buf[ sizeof(buf)-1 ] = ‘\0’;
memset( buf,0,sizeof(buf));strncpy( buf, string, sizeof(buf)-1);orstrncpy( buf, string, sizeof(buf)-1);buf[ sizeof(buf)-1 ] = ‘\0’;
沒有留言:
張貼留言