易春木

Feed Rss

C語言-使用strncpy複製字串

07.09.2010, IT開發, by , 6,911 人次 .

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';

閱讀這篇文章的讀者也會看:

1 則回應給 C語言-使用strncpy複製字串

  1. :.: I am very thankful to this topic because it really gives up to date information -;*

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>