軟件素材---linux C語言:拼接字符串函數 strcat的用例(與char數組聯合使用挺好)

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

【原型】

1

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

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

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

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

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

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

1

2

3

4

5

6

7

8

9

10

11

12

#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. 

 

Ref:

https://www.cnblogs.com/lvchaoshun/p/5936168.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章