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

strcat、strcpy、memcpy 的使用注意

时间:2015-03-28 01:11:40      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

 1     char *p = "hello";//5 个长度
 2 
 3     int len = strlen(p)+1 ;
 4 
 5     //char *str = (char *)malloc(sizeof(char)*len);
 6     char str[90] = "nihaoma";
 7     //memset(str, 0, len);
 8     //strcpy(str, p);
 9     strcat(str, p);//str 必须有初始化
10     //memcpy(): 需要为 str 多分配一个空间,然后系统才能自动添加 \0
11     //memcpy(str, p, len);
12     len = strlen(str);
13 
14     printf("strlen(str):%d\n", len);
15     printf("%s\n", str);
16 
17     //char destination[25];
18     //char *blank = " ", *c = "C++", *Borland = "Borland";
19 
20     ////strcpy 自动加 \0  那么后面使用 strcat 也不会影响
21     //strcpy(destination, Borland);
22     //strcat(destination, blank);
23     //strcat(destination, c);
24 
25     //printf("%s\n", destination);
26 
27 
28 
29     system("pause");

 

strcat、strcpy、memcpy 的使用注意

标签:

原文地址:http://www.cnblogs.com/yougmi/p/4373483.html

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