C++复制字符串函数_snprintf的使用

char c2[20] = "ganquanfu";
char c1[256];
c1[sizeof(c1)-1] = 0;
_snprintf(c1, sizeof(c1), "%s", c2);
if(c1[sizeof(c1)-1]!=0)
{
cout << "warning: string is truncated" <<endl;
c1[sizeof(c1)-1]=0;
}
cout << c1 << endl;

posted @ 2013-07-09 19:52  Predator  阅读(1137)  评论(0编辑  收藏  举报