C語言拼接字符串 -- 使用strcat()函數


【頭文件】#include <string.h>

【原型】

char *strcat(char *dest, const char *src);

【參數】: dest 為目標字符串指針,src 為源字符串指針。

strcat() 會將參數 src 字符串復制到參數 dest 所指的字符串尾部;dest 最后的結束字符 NULL 會被覆蓋掉,並在連接后的字符串的尾部再增加一個 NULL。

【注意】 dest 與 src 所指的內存空間不能重疊,且 dest 要有足夠的空間來容納要復制的字符串

【返回值】 返回dest 字符串起始地址。

【實例】連接字符串並輸出。

    #include <stdio.h>
    #include <string.h>
    int main ()
    {
        char str[80];
        strcpy (str,"these ");
        strcat (str,"strings ");
        strcat (str,"are ");
        strcat (str,"concatenated.");
        puts (str);
        return 0;
    }

輸出結果:
these strings are concatenated. 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM