Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

C語言-使用strncpy複製字串

當使用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’;

One thought on “C語言-使用strncpy複製字串

發表迴響