zoukankan      html  css  js  c++  java
  • 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");
  • 相关阅读:
    nginx安装:linux环境下安装包安装
    Effective C++
    Win32 Msg
    C++ 17
    Win32 Threads
    Exceptional C++
    C++11
    STL 分类
    C++类型转换
    红黑树
  • 原文地址:https://www.cnblogs.com/yougmi/p/4373483.html
Copyright © 2011-2022 走看看