C 标准库

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

1// 2// Created by zhangrxiang on 2018/2/3. 3// 4 5#include <stdio.h> 6#include <string.h> 7 8int main() { 9 char str[] = "Hello C"; 10 char str2[50] = "Hello World"; 11 printf("%s\n", str);//Hello C 12 printf("%s\n", str2);//Hello World 13 char *str3 = strcat(str2, str); 14 printf("%s\n", str2);//Hello WorldHello C 15 printf("%s\n", str3);//Hello WorldHello C 16 str3 = "hi everyone"; 17 printf("%s\n", str3);//hi everyone 18 printf("%s\n", str2);//Hello WorldHello C 19 str2[2] = 'L'; 20 str[2] = 'L'; 21 str[0] = 'h'; 22 printf("%s\n", str2);//HeLlo WorldHello C 23 printf("%s\n", str);//heLlo C 24 25 char *str4 = "hi world"; 26// str[0] = 'H'; //行为为定义 h 27 printf("%c\n",str4[0]);//h 28 printf("%s\n",str4); 29 30 char str5[80]; 31 strcpy (str5,"these "); 32 strcat (str5,"strings "); 33 strcat (str5,"are "); 34 strcat (str5,"concatenated."); 35 puts (str5); 36 //these strings are concatenated. 37 38 return 0; 39}

文章参考

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

Opencv中Mat矩阵相乘——点乘、dot、mul运算详解

Opencv中Mat矩阵相乘——点乘、dot、mul运算详解2016年09月02日00:00:36 \牧野(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fme.csdn.net%2Fdcrmg) 阅读数:59593