C 标准库 - string.h之strcat使用
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;
}
文章参考
- http://www.cplusplus.com/reference/cstring/strcat/
- http://zh.cppreference.com/w/c/string/byte/strcat
- https://linux.die.net/man/3/strcat
C 标准库 - string.h之strcat使用的更多相关文章
- C 标准库 - string.h
C 标准库 - string.h This header file defines several functions to manipulate C strings and arrays. stri ...
- C标准库<string.h>实现
本文地址:http://www.cnblogs.com/archimedes/p/c-library-string.html,转载请注明源地址. 1.背景知识 <string.h>中声明的 ...
- C标准库string.h中几个常用函数的使用详解
strlen 计算字符串长度 size_t strlen(const char *str) 计算字符串 str 的长度,直到空结束字符,但不包括空结束字符. 函数实现: int Strlen(cons ...
- C 标准库 - string.h之memmove使用
memmove Move block of memory Copies the values of num bytes from the location pointed by source to t ...
- C 标准库 - string.h之memcpy使用
memcpy Copy block of memory Copies the values of num bytes from the location pointed to by source di ...
- C 标准库 - string.h之memcmp使用
memcmp Compare two blocks of memory. Compares the first num bytes of the block of memory pointed by ...
- C 标准库 - string.h之memchr使用
memchr Locate character in block of memory,Searches within the first num bytes of the block of memor ...
- C 标准库 - string.h之strlen使用
strlen Returns the length of the C string str. The length of a C string is determined by the termina ...
- C 标准库 - string.h之strpbrk使用
strpbrk Locate characters in string,Returns a pointer to the first occurrence in str1 of any of the ...
随机推荐
- delphi中sql实现while循环插入,不存在则插入
' declare @i int; '+ ' set @i=0; '+ ' while @i<4 '+ ' begin '+ ' insert into NBCommission(Type,It ...
- TDE--相关Demo
SQL Server 2008引入透明数据加密(Transparent Data Encryption),它允许你完全无需修改应用程序代码而对整个数据库加密.当一个用户数据库可用且已启用TDE时,在写 ...
- 牛客网提高组模拟赛第七场 T3 洞穴(附bitset介绍)
就是DP. 我们可以很简单的想到要枚举中间点,进行边数的转移. 但是因为边长数据范围很大,所以我们考虑log的倍增. 状态设计为\(dp[i][j][k]\),为从节点\(i\)走\(2^k\)步能否 ...
- 如果使用安卓4.4的SD卡?
安卓4.4默认情况下,后安装的程序无权写入数据到SD卡中,那么是否我们就不能用了?看了很多文章,都说要Root,随后修改配置文件.我觉得这不是很好的方法,Root之后的安卓会有很大风险,这不是最好的办 ...
- 15、xtrabackup 全量备份
xtrabackup 全量备份与恢复 安装 yum install https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2. ...
- 案例2-tomcat自启动脚本
适用于ubuntu,centos 涉及知识点 1. 函数 2. case语句 #!/bin/bash #chkconfig: #description:Tomcat service #pidfile: ...
- ajax方法参数详解与$.each()和jquery里面each方法的区别
JQuery中$.ajax()方法参数详解 url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为g ...
- >>> 主页链接
服 务 & SDK 网易云信|真正稳定的IM即时通讯云服务 微信小程序开发工具下载 百度LBS开放平台 ( 百度地图API示例) 微信JSSDK说明文档 (在线demo) 园 友 京东开涛 W ...
- Bootrap 项目实战(微金所前端首页)第二部分(首页源码)
首页源码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- elasticsearch-sql插件
elasticsearch DSL语法有些时候比较难懂换成SQL好处理一些,网上找到一个插件 https://github.com/NLPchina/elasticsearch-sql 安装elast ...