软件素材---linux C语言:拼接字符串函数 strcat的用例(与char数组联合使用挺好)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35865125/article/details/83043104

【头文件】#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

猜你喜欢

转载自blog.csdn.net/qq_35865125/article/details/83043104
今日推荐