跳轉到內容

C++ 程式設計/程式碼/標準 C 庫/函式/strncpy

來自 Wikibooks,開放的書籍,為開放的世界
語法
#include <cstring>
char *strncpy( char *to, const char *from, size_t count );

strncpy() 函式最多複製 count 個字元從 from 到字串 to。只有當 from 的字元數少於 count 時,才會用 '\0' 字元填充剩餘部分。return 值是結果字串。

注意
使用未用 '\0' 字元填充的字串會導致安全漏洞。

相關主題
memcpy - strchr - strcpy - strncat - strncmp
華夏公益教科書