C String concatenation.

Source: Internet
Author: User

Complete code:

1 # include <stdio. h> 2 # include <string. h> 3 # include <malloc. h> 4 5 # define true 1 6 # define false 0 7 8 char * 9 strca (char *, char *); 10 11 char * 12 join1 (char *, char *); 13 14 int15 main (void) {16 char * A = "hello"; 17 char * B = "de Me "; 18 printf ("% s \ n", strca (A, B); 19} 20 21 char * 22 strca (char * des, char * SRC) {23 char * r = (char *) malloc (sizeof (strlen (DES) + sizeof (strlen (SRC) + 1); // The tail is stored in '\ 0'. Terminator. 24 if (! R) {25 printf ("out of memory! \ N "); 26 return false; 27} 28 char * TMP = r; // Save the first address. 29/* While (* r ++ = * des ++) 30 */; 31 32 While (* des) 33 * r ++ = * des ++; 34 35 while (* r ++ = * SRC ++) 36; 37 return TMP; 38}

 

I am playing C basics recently, but I haven't fully understood the comment section of strca function (29th ~ 30 rows) Why can't the code achieve the desired effect? I started to study disassembly of X86 and C in the past two days. I have little information in China, and I am a little busy with the recent postgraduate review. Come on.

C String concatenation.

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.