/*************************************** ************************
(C language)
AUTHOR: liuyongshui
DATE :********
**************************************** ***********************/
/*
Question 9: Compile the stringcat function,
Achieve string connection,
The program needs to use a pointer to access the string
*/
# Include <stdio. h>
# Deprecision MAX 100
Char * StringCat (char * source, const char * dest); // original function declaration
Int main ()
{
Char s1 [MAX] = "I LOVE ";
Char * s2 = "C ++ and C language! ";
StringCat (s1, s2); // string connection
Printf ("% s \ n", s1 );
Return 0;
}
// Function Definition
Char * StringCat (char * source, const char * dest)
{
// Int I = 0;
// Int j;
While (* source ++); // null statement to move the pointer to the end
* Source --; // move one digit forward, because one digit is moved backward before the end of the previous step.
While (* dest! = '\ 0') // It ends when' \ 0' is encountered. This sentence is equivalent to while (* dest! = '\ 0 ')
{
* Source ++ = * dest ++; // assign the value in dest to source
}
Return 0;
}