• strcat、strcpy、memcpy 的使用注意


     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 多分配一个空间,然后系统才能自动添加 
    11     //memcpy(str, p, len);
    12     len = strlen(str);
    13 
    14     printf("strlen(str):%d
    ", len);
    15     printf("%s
    ", str);
    16 
    17     //char destination[25];
    18     //char *blank = " ", *c = "C++", *Borland = "Borland";
    19 
    20     ////strcpy 自动加   那么后面使用 strcat 也不会影响
    21     //strcpy(destination, Borland);
    22     //strcat(destination, blank);
    23     //strcat(destination, c);
    24 
    25     //printf("%s
    ", destination);
    26 
    27 
    28 
    29     system("pause");
  • 相关阅读:
    StarUML
    第二周周二日报
    第二周周一日报
    第一周周末报
    第一周周四日报
    第一周第三天日报
    软件开发总结
    构建之法总结
    《构建之法》第六章
    个人日志7
  • 原文地址:https://www.cnblogs.com/yougmi/p/4373483.html
Copyright © 2020-2023  润新知