Implementation of strcat functions and strcat Functions
Prototype extern char * strcat (char * dest, char * src );
Usage# Include <string. h>
FunctionAdd the string indicated by src to the end of dest (overwrite '\ 0' at the end of dest) and' \ 0 '. Returns the pointer to dest.
DescriptionThe memory areas specified by src and dest cannot overlap and dest must have enough space to hold src strings..
Example
Char str4 [] = "Hello world ";
Char str5 [] = "Hello World ";
Cout <strcat (str4, str5) <endl;
An error occurs because str4 does not have enough space.
The following is an implementation of my own. I hope to correct it !!!
# Include "stdafx. h "# include <iostream> # include <assert. h> using namespace std; // connection string char * mystrcat (char * destStr, const char * srcStr) // What if the two strings are the same string? {Assert (destStr! = NULL & srcStr! = NULL); char * temp = destStr; while (* destStr! = '\ 0') {++ destStr;} while (* destStr ++ = * srcStr ++) NULL; return temp; // to implement chained operations, return the destination address} int _ tmain (int argc, _ TCHAR * argv []) {char str1 [25] = "Hello world "; char str2 [] = "Hello World"; cout <mystrcat (str1, str2) <endl; return 0 ;}