The method of realizing Strcat string Connection library function in C + + _c language

Source: Internet
Author: User
Prototype
extern Char *strcat (char *dest,char *src);
usage
#include <string.h>
function
Add the string src refers to the end of the dest (cover the ' dest ' at the end of the ending) and add ' the '.
description
The memory regions referred to in SRC and dest cannot overlap and dest must have enough space to hold the SRC string.
Returns a pointer to Dest.
examples
char str4[] = "Hello World";
Char str5[] = "Hello World";
cout << strcat (STR4,STR5) << Endl;
There's going to be a mistake because STR4 don't have enough space
Here is a realization of my own, deficiencies, but also to correct the!!!
Copy Code code as follows:

#include "stdafx.h"
#include <iostream>
#include <assert.h>
using namespace Std;
Connection string
char* Mystrcat (char* deststr,const char* srcstr)//If two strings are the same string?
{
ASSERT (deststr!= null && srcstr!= null);
char* Temp=deststr;
while (*deststr!= ' ")
{
++DESTSTR;
}
while (*deststr++ = *srcstr++)
NULL;
return temp; In order to achieve the chain operation, the destination address is returned
}
int _tmain (int argc, _tchar* argv[])
{
Char str1[25] = "Hello World";
Char str2[] = "Hello World";
cout << Mystrcat (STR1,STR2) << Endl;
return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.