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 ...
随机推荐
- shiro注解@RequiresPermissions多权限任选一参数用法
@RequiresPermissions(value={"xxx:xxx","xxx:xxx"},logical=Logical.OR)
- 菜鸟的Xamarin.Forms前行之路——绪言
作者入门时间不是很久,差不多一年,期间自学的东西比较杂乱,到目前为止,编程方面的知识比较薄弱.之所以做这个系列,也只是因为做了两个月的Xamarin.Forms方面的东西,由于资料和自身实力的原因,过 ...
- BT Tracker的原理及.Net Core简单实现Tracker Server
最近很忙,自上次Blog被盗 帖子全部丢失后也很少时间更新Blog了,闲暇在国外站点查阅资料时正好看到一些Tracker 的协议资料,也就今天记录并实践了下,再次分享给大家希望可以帮到需要的小伙伴. ...
- C# 汉语生成拼音(微软官方方案)
项目开发中用户的登录名是管理员在后台输入汉字姓名后自动生成的拼音.例如输入:张三,则登录名自动生成ZHANGSAN. 我在网上查阅了很多方法: 如:http://blog.csdn.net/nengz ...
- 搜索实时个性化模型——基于FTRL和个性化推荐的搜索排序优化
本文来自网易云社区 作者:穆学锋 简介:传统的搜索个性化做法是定义个性化的标签,将用户和商品通过个性化标签关联起来,在搜索时进行匹配.传统做法的用户特征基本是离线计算获得,不够实时:个性化标签虽然具有 ...
- JDBC mysql 中文查询不到数据解决
问题现象: Selenium自动测试中,使用JDBC查询mysql数据库中数据,查询条件为中文,例如: select * from XXX where name ='我是测试数据'; 查询结果为空:但 ...
- 四、Centos linux系统优化
1. 无论是哪个版本的linux,都会提供32位和64位的两个版本的镜像. i386为32位 x86_64为64位 两者的区别: 1)目标:需要大量的内存需求的行业为64位,普通用户的需求为3 ...
- 原生态js单个点击展开收缩
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【spring】SpringBoot之Servlet、Filter、Listener配置
转载自 http://blog.csdn.net/king_is_everyone/article/details/53116744 1.介绍 通过之前的文章来看,SpringBoot涵盖了很多配置, ...
- PyQt5(4)——菜单栏(使用外部exe)
图像化建立菜单栏: ① 双击输入名称 就可以喽 如何添加工具栏呢: 新建一个快捷工具,拖到快捷栏,出现红色的小竖线. 至此 就完成了菜单栏和快捷方式的建立. 补充: python 如何调用外部的e ...