博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C 标准库 - string.h之strcat使用
阅读量:4494 次
发布时间:2019-06-08

本文共 1768 字,大约阅读时间需要 5 分钟。

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 
#include
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;}

文章参考

转载于:https://www.cnblogs.com/zhangrxiang/p/8411162.html

你可能感兴趣的文章
[leetcode] Minimum Path Sum
查看>>
PAT乙级1021.个位数统计(15 分)
查看>>
强化学习Q-Learning算法详解
查看>>
Spring MVC
查看>>
winform treeview 复选框,父节点子节点联动Bug
查看>>
C#_委托类型以及Action/Fanc_2018Oct
查看>>
es数组去重的简写
查看>>
Training Logisches Denken
查看>>
谁分配谁释放
查看>>
正则表达式
查看>>
Java集合之LinkedHashSet源码分析
查看>>
David Silver强化学习Lecture1:强化学习简介
查看>>
开源项目
查看>>
mvc4 找到多个与名为“xx”的控制器匹配的类型
查看>>
unix系统内核优点
查看>>
协议(五)-从电报机到智能手机
查看>>
Solr学习
查看>>
HDU-4628 Pieces 搜索 | DP
查看>>
动态代理
查看>>
C++ 错误积累
查看>>