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

strcpy,strncpy,strcmp函数

时间:2014-08-31 22:47:51      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   ar   2014   div   log   sp   



void
mystrcpy(char *dst,const char * src)//当dst的内存长度不够时将会产生溢出 { if (dst==NULL||src==NULL) { exit(0); } while(*src!=\0) *dst++=*src++; *dst=\0; } int main() { char src[]="hello world"; char dst[]="zzzzzz"; strcpy(dst,src);//错误 发生越界 cout<<strcmp(src,dst)<<endl;//比较两个字符串大小 strncpy(dst,src,sizeof(dst)-1);//正确 cout<<dst<<endl; cout<<strcmp(src,dst)<<endl; }

bubuko.com,布布扣

strcpy,strncpy,strcmp函数

标签:style   blog   http   color   ar   2014   div   log   sp   

原文地址:http://www.cnblogs.com/mu-tou-man/p/3948250.html

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