strcat

  • Appends a copy of the source string to the destination string. The terminating null character in destination is overwritten by the first character of source, and a null-character is included at the end of the new string formed by the concatenation of both in destination.
  • 后附 src 所指向的空终止字节字符串的副本到 dest 所指向的空终止字节字符串的结尾。字符 src[0] 替换 dest 末尾的空终止符。产生的字节字符串是空终止的。
  • 若目标数组对于 src 和 dest 的内容以及空终止符不够大,则行为未定义。
  • 若字符串重叠,则行为未定义。
  • 若 dest 或 src 不是指向空终止字节字符串的指针,则行为未定义。
char * strcat ( char * destination, const char * source );

Parameters

destination

  • Pointer to the destination array, which should contain a C string, and be large enough to contain the concatenated resulting string.
  • 指向要后附到的空终止字节字符串的指针

source

  • C string to be appended. This should not overlap destination.
  • 指向作为复制来源的空终止字节字符串的指针

Return Value

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

Example

//
// Created by zhangrxiang on 2018/2/3.
// #include <stdio.h>
#include <string.h> int main() {
char str[] = "Hello C";
char str2[50] = "Hello World";
printf("%s\n", str);//Hello C
printf("%s\n", str2);//Hello World
char *str3 = strcat(str2, str);
printf("%s\n", str2);//Hello WorldHello C
printf("%s\n", str3);//Hello WorldHello C
str3 = "hi everyone";
printf("%s\n", str3);//hi everyone
printf("%s\n", str2);//Hello WorldHello C
str2[2] = 'L';
str[2] = 'L';
str[0] = 'h';
printf("%s\n", str2);//HeLlo WorldHello C
printf("%s\n", str);//heLlo C char *str4 = "hi world";
// str[0] = 'H'; //行为为定义 h
printf("%c\n",str4[0]);//h
printf("%s\n",str4); char str5[80];
strcpy (str5,"these ");
strcat (str5,"strings ");
strcat (str5,"are ");
strcat (str5,"concatenated.");
puts (str5);
//these strings are concatenated. return 0;
}

文章参考

C 标准库 - string.h之strcat使用的更多相关文章

  1. C 标准库 - string.h

    C 标准库 - string.h This header file defines several functions to manipulate C strings and arrays. stri ...

  2. C标准库<string.h>实现

    本文地址:http://www.cnblogs.com/archimedes/p/c-library-string.html,转载请注明源地址. 1.背景知识 <string.h>中声明的 ...

  3. C标准库string.h中几个常用函数的使用详解

    strlen 计算字符串长度 size_t strlen(const char *str) 计算字符串 str 的长度,直到空结束字符,但不包括空结束字符. 函数实现: int Strlen(cons ...

  4. C 标准库 - string.h之memmove使用

    memmove Move block of memory Copies the values of num bytes from the location pointed by source to t ...

  5. C 标准库 - string.h之memcpy使用

    memcpy Copy block of memory Copies the values of num bytes from the location pointed to by source di ...

  6. C 标准库 - string.h之memcmp使用

    memcmp Compare two blocks of memory. Compares the first num bytes of the block of memory pointed by ...

  7. C 标准库 - string.h之memchr使用

    memchr Locate character in block of memory,Searches within the first num bytes of the block of memor ...

  8. C 标准库 - string.h之strlen使用

    strlen Returns the length of the C string str. The length of a C string is determined by the termina ...

  9. C 标准库 - string.h之strpbrk使用

    strpbrk Locate characters in string,Returns a pointer to the first occurrence in str1 of any of the ...

随机推荐

  1. php 将二维数组批量插入到数据库中

    $arr = array( array(,'name'=>'ceshi4'), array(,'name'=>'ceshi5'), array(,'name'=>'ceshi6'), ...

  2. Android-Spinner下拉列表

    在布局Layout文件中定义Spinner: <?xml version="1.0" encoding="utf-8"?> <LinearLa ...

  3. C# Winform 使用Application.Exit重新启动应用程序example

    Application.Exit会在所有前台线程退出后,退出应用, Environment.Exit则立即终止进程,相比之下Environment.Exit更狠些 private static voi ...

  4. 曲苑杂坛--查看CPU配置

    ​--===================================================--查看CPU配置SELECT cpu_count AS [Logical CPU Coun ...

  5. RabbitMQ与.net core(四) 消息的优先级 与 死信队列

    1.消息的优先级 假如现在有个需求,我们需要让一些优先级最高的通知推送到客户端,我们可以使用redis的sortedset,也可以使用我们今天要说的rabbit的消息优先级属性 Producer代码 ...

  6. centos7 守护进程

    ASP.NET Core应用程序发布linux在shell中运行是正常的.可一但shell关闭网站也就关闭了,所以要配置守护进程, 用的是Supervisor,本文主要记录配置的过程和过程遇到的问题 ...

  7. MongoDB高级知识-易扩展

    MongoDB高级知识-易扩展 应用程序数据集的大小正在以不可思议的速度增长.随着可用宽带的增长和存储器价格的下跌,即使是一个小规模的应用程序,需要存储的数据也可能大的惊人,甚至超出了很多数据库的处理 ...

  8. Python——使用matplotlib绘制柱状图

    Python——使用matplotlib绘制柱状图 1.基本柱状图           首先要安装matplotlib(http://matplotlib.org/api/pyplot_api.htm ...

  9. Java面向对象之异常(throw与throws)

    一.基础概念 1.throw和throws的区别: 位置不同:throws用在函数上,后面跟的是异常类,可以跟多个. throw用在函数内,后面跟的是异常对象. 功能不同:throws用来声明异常,让 ...

  10. PHP删除一个目录下的所有文件,不删除文件夹

    /*删除指定目录下的文件,不删除目录文件夹*/ function delFile($dirName){ if(file_exists($dirName) && $handle=open ...