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. java 添加到数据库的数据没有时分秒

    检查hibernate实体类的映射文件日期类型把date 改为 java.util.Date

  2. ASP.NET程序从IIS6移植到IIS7时出现500.22错误(转)

    最可能的原因: •    此应用程序在 system.web/httpModules 节中定义配置. 可尝试的操作: •    将配置迁移到 system.webServer/modules 节.也可 ...

  3. WebApi与Mvc的区别

    ASP.NET Mvc是基于ASP.NET管道设计的框架,但是Mvc应用程序只能在iis中运行,而WebApi框架既可以寄宿在IIs上也可以在Self-Host上进行处理. Mvc和webapi都有相 ...

  4. K8s集群安装--最新版 Kubernetes 1.14.1

    K8s集群安装--最新版 Kubernetes 1.14.1 前言 网上有很多关于k8s安装的文章,但是我参照一些文章安装时碰到了不少坑.今天终于安装好了,故将一些关键点写下来与大家共享. 我安装是基 ...

  5. 21天学通C++学习笔记(九):类和对象

    1. 类和对象 现实中的人等事物往往具备一些特征并且可以做某些事情,要在程序中模拟这些事物,需要一个结构,将定义其属性(数据)以及其可用这些属性执行的操作(函数)整合在一起.这种结构就是类,而这种结构 ...

  6. TOMCAT在POST方法提交参数丢失问题

    最近写程序发现post参数接收不到了,jdk,eclipse,jar包,换了多次都不行,后来看到网上一篇文章: 随后设置Tomcat中POST方式提交数据大小: maxPostSize="0 ...

  7. vue.js 知识点(四)

    看完了vue.js的官方文档,大概对这些知识有了那么一点的了解了,但是很多具体的运用还不太清楚,现在就总结一下,关于其中的一些知识点的运用: v-bind:  动态绑定指令,默认情况下,是给html ...

  8. [agc004e]Salvage Robots dp

    Description 蛤蟆国的领土我们可以抽象为H*W的笼子,在这片蛤土上,有若干个机器人和一个出口,其余都是空地,每次蛤蟆会要求让所有的机器人向某个方向移动一步,当机器人移动到出口时会被蛤蟆活摘出 ...

  9. Redis数据持久化,安全

    一.redis数据持久化 由于redis是一个内存数据库,如果系统遇到致命问题需要关机或重启,内存中的数据就会丢失,这是生产环境所不能允许的.所以redis提供了数据持久化的能力. redis提供了两 ...

  10. iOS 图片的存储以及读取和删除

    将图片存储到本地 NSArray *dirArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask ...