woaidongmao

文章均收录自他人博客,但不喜标题前加-[转贴],因其丑陋,见谅!~
随笔 - 1469, 文章 - 0, 评论 - 661, 引用 - 0
数据加载中……

strncpy的注意事项

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.

 

错误的使用

strncpy(di.group, adg.group, sizeof(di.group) - 1);

正确的应该为

strncpy(di.group, adg.group, sizeof(di.group) - 1);

di.group[sizeof() - 1] = 0;

posted on 2009-09-23 13:27 肥仔 阅读(381) 评论(0)  编辑 收藏 引用 所属分类: C++ 基础


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理