Question 9: Compile the stringcat function to connect strings. in the program, you must use pointers to access strings.

Source: Internet
Author: User

/*************************************** ************************
(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;
}

Related Article

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.