1、使用strcat进行字符串拼接

#include <stdio.h>
#include <stdlib.h>
#include <string.h> int main() {
char *firstName = "Theo";
char *lastName = "Tsao";
char *name = (char *) malloc(strlen(firstName) + strlen(lastName));
strcpy(name, firstName);
strcat(name, lastName);
printf("%s\n", name);
return 0;
}

2、使用sprintf进行字符串拼接

#include <stdio.h>
#include <stdlib.h>
#include <string.h> int main() {
char *firstName = "Theo";
char *lastName = "Tsao";
char *name = (char *) malloc(strlen(firstName) + strlen(lastName));
sprintf(name, "%s%s", firstName, lastName);
printf("%s\n", name);
return 0;
}

C语言字符串拼接的更多相关文章

  1. C语言实现字符串拼接

    #include <stdio.h>#include <stdlib.h>#include <string.h> char* str_contact(const c ...

  2. 【C语言学习笔记】字符串拼接的3种方法 .

    昨天晚上和@buptpatriot讨论函数返回指针(malloc生成的)的问题,提到字符串拼接,做个总结. #include<stdio.h> #include<stdlib.h&g ...

  3. C语言学习笔记之字符串拼接的2种方法——strcat、sprintf

    本文为原创文章,转载请标明出处 1. 使用strcat进行字符串拼接 #include <stdio.h> #include <stdlib.h> #include <s ...

  4. 嵌入式-C语言基础:字符串拼接函数strcat

    #include<stdio.h> #include <string.h> //实现字符串拼接 char * mystrcat(char * dest,char * src) ...

  5. Objective的字符串拼接 似乎没有Swift方便,但也可以制做一些较为方便的写法

    NSString *str1 = @"字符串1"; NSString *str2 = @"字符串2"; //在同样条件下,Objective的字符串拼接 往往只 ...

  6. C语言字符串操作常用库函数

    C语言字符串操作常用库函数 *********************************************************************************** 函数 ...

  7. c语言字符串操作大全

     C语言字符串操作函数 函数名: strcpy 功  能: 拷贝一个字符串到另一个 用  法: char *stpcpy(char *destin, char *source); 程序例: #incl ...

  8. C 语言字符串连接的 3种方式

    C 语言字符串连接的 3种方式 #include<stdio.h> #include<stdlib.h> #include<string.h> char *join ...

  9. 13-C语言字符串函数库

    目录: 一.C语言字符串函数库 二.用命令行输入参数 回到顶部 一.C语言字符串函数库 1 #include <string.h> 2 字符串复制 strcpy(参数1,参数2); 参数1 ...

随机推荐

  1. keepalived 预防脑裂检测脚本

    1 检查vip [root@mysql2 keepalived]# cat /etc/keepalived/check_brain_keepalived.sh #!/bin/bash # 检查脑裂的脚 ...

  2. js日期date对象

    js日期 日期对象的一些属性和方法 var date = new Date() date.toString() // "Tue Jan 29 2019 22:58:13 GMT+0800 ( ...

  3. 科学计算工具Numpy简介

    Numpy(Numerical Python) Numpy:提供了一个在Python中做科学计算的基础库,重在数值计算,主要用于多维数组(矩阵)处理的库.用来存储和处理大型矩阵,比Python自身的嵌 ...

  4. leetcode876

    class Solution { public: ListNode* middleNode(ListNode* head) { if (head == NULL) { return nullptr; ...

  5. C++深度解析教程学习笔记(3)函数的扩展

    1.内联函数 1.1.常量与宏的回顾 (1)C++中的 const 常量可以替代宏常数定义,如: ; //等价于 #define A 3 (2)C++中是否有解决方案,可以用来替代宏代码片段呢? 1. ...

  6. AMFObject 数据格式浅析

    amf.h中关于 AMFObject 是这样的定义的: typedef struct AMFObject { int o_num; struct AMFObjectProperty *o_props; ...

  7. python实现文件下载的方法总结

    前端时间遇到一个通过url下载文件的需求,只需要简单的编写一个py脚本即可.从网上搜了下python实现文件下载的方法,总结如下,备查. 以下方法均已测试,环境win8.1  python2.6/2. ...

  8. string基本字符系列容器(二)

    string对象作为vector元素 string对象可以作为vector向量元素,这种用法类似字符串数组. #include<string> #include<vector> ...

  9. conda create -n AlphaPose2018 python=2.7

    conda create -n AlphaPose2018 python=2.7Solving environment: done ==> WARNING: A newer version of ...

  10. suse10配置SSH无密码登录的方法

    RSH配置(集群中的每台机器执行以下操作) 1.因SUSE LINUX不自带RSH-SERVER服务,所以首先要去从www.rpmfind.net 下载rsh-server服务的RPM包. 然后切换到 ...