C语言拼接字符串 -- 使用strcat()函数
Posted 白菜菜白
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.
以上是关于C语言拼接字符串 -- 使用strcat()函数的主要内容,如果未能解决你的问题,请参考以下文章