字符串拼接

#include <iostream>
#include <cstring>
#include <cstdlib>

 

char *mystrcat(char *dst,const char *src) //用自己的方式实现strcat函数功能

  {
       char *p=dst;  //下面的操作会改变目的指针指向,先定义一个指针记录dst
       while(*p!='\0')p++;
       while(*src != '\0')*p++=*src++;
       *p='\0';
  return dst;  
  }
 
int main()
{
    using namespace std;
    char d[20] = "GoldenGlobal";
    char* s = "View";
    system("cls");
    mystrcat(d,s);
    cout << d << endl;
    system("pause");
    return 0;
}

 

 

posted @ 2020-07-26 08:06  洪豆豆的记录  阅读(117)  评论(0编辑  收藏  举报