C 库函数 - strcat()

描述

C 库函数 char strcat(char dest, const char *src)src 所指向的字符串追加到 dest 所指向的字符串的结尾。

声明

下面是 strcat() 函数的声明。

  1. char *strcat(char *dest, const char *src)

参数

  • dest — 指向目标数组,该数组包含了一个 C 字符串,且足够容纳追加后的字符串。
  • src — 指向要追加的字符串,该字符串不会覆盖目标字符串。

返回值

该函数返回一个指向最终的目标字符串 dest 的指针。

实例

下面的实例演示了 strcat() 函数的用法。

  1. #include <stdio.h>
  2. #include <string.h>
  3. int main ()
  4. {
  5. char src[50], dest[50];
  6. strcpy(src, "This is source");
  7. strcpy(dest, "This is destination");
  8. strcat(dest, src);
  9. printf("最终的目标字符串: |%s|", dest);
  10. return(0);
  11. }

让我们编译并运行上面的程序,这将产生以下结果:

  1. 最终的目标字符串: |This is destinationThis is source|