码迷,mamicode.com
首页 > 其他好文 > 详细

关于lstrcpyn与strncpy的一点区别

时间:2015-03-06 12:49:01      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

这两个函数作用相近,很容易用错。
LPTSTR lstrcpyn(      

    LPTSTR lpString1,
    LPCTSTR lpString2,
    int iMaxLength
);
Specifies the number of TCHAR values to be copied from the string pointed to by lpString2 into the buffer pointed to by lpString1, including a terminating null character. This refers to bytes for ANSI versions of the function or WCHAR values for Unicode versions. 
从lpString2中向lpString1复制iMaxLength个字节,包括/0,也就是实际复制iMaxLength-1个字节

char *strncpy(
   char *strDest,
   const char *strSource,
   size_t count 
);

The strncpy function copies the initial count characters of strSource to strDest and returns strDest. If count is less than or equal to the length of strSource, a null character is not appended automatically to the copied string. If count is greater than the length of strSource, the destination string is padded with null characters up to length count. The behavior of strncpy is undefined if the source and destination strings overlap. 

strSource向strDest中复制count个字节,如果strSource长度不够,后面的字节用/0补齐

关于lstrcpyn与strncpy的一点区别

标签:

原文地址:http://blog.csdn.net/u011391040/article/details/44096875

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!