c 字串的拼接.

來源:互聯網
上載者:User

標籤:des   style   blog   color   io   ar   div   sp   代碼   

完整代碼:

 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 = "你好";17     char *b = "de我";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);    //尾部存放‘\0‘中終止符.24     if(!r) {25         printf("out of memory!\n");26         return FALSE;27     }28     char *tmp = r;    //儲存首地址.29 /*    while( *r++ = *des++ )30     */    ;31 32     while( *des )33         *r++ = *des++;34     35     while( *r++ = *src++ )36         ;37     return tmp;38 }

 

最近在打C基礎,現在還沒完全弄明白 strca 函數中,注釋部分(第 29~30 行)的代碼為什麼不能達到想要的效果.這兩天才開始研究 x86和c的disassembly,國內的資料少,再加上最近複習考研,有點忙,慢慢來吧.

c 字串的拼接.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.