C语言,字符串的拼接.strcat()和sprintf()函数之间的比较
2018-01-18 16:46
387 查看
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char *ch1 = "hello"; char *ch2 = "world"; char *temp = (char *)malloc(strlen(ch1) + strlen(ch2)); strcat(temp,ch1); strcat(temp,ch2); printf("Test temp = %s\n",temp); strcat(temp,"\'"); printf("Test1 temp = %s\n",temp); free(temp); char *temp1 = {0};//必须初始化 sprintf(temp1,"%s%s from \'li\'\n",ch1,ch2); printf("Test temp1 = %s",temp1); return 0; }
输出结果: Test temp = hello world
Test1 temp = hello world'
Test temp1 = hello world from 'li'
相关文章推荐
- C语言 字符串常用函数(计算长度,拷贝,拼接,比较)
- C语言strcat()函数:连接字符串
- C语言中字符串常用函数strcat与strcpy的用法介绍
- 在8位单片机上面实现字符串的拼接(单片机上strcat的函数的实现)
- C语言snprintf()函数:将格式化的数据写入字符串—sprintf()
- c++拼接字符串效率比较(+=、append、stringstream、sprintf)
- 自定义字符串处理函数(求长度,拷贝、拼接、比较)--两种方法
- C语言字符串函数详解 strcpy、strcmp、strcat、strlen、strstr
- C语言数字与字符串转换 atoi()函数、itoa()函数、sprintf()函数
- 字符串处理函数strlen、strcpy、strcat、strcmp和convert的C语言实现
- 自定义字符串拼接函数my_strcat()
- strcat字符串拼接函数
- 字符串操作(拷贝,比较,拼接等函数)
- 字符串 函数sprintf、strcpy 、strncpy及 memcpy , strftime,strcat
- C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
- C语言strcat()函数:连接字符串
- C语言strcat()函数:连接字符串
- C语言字符串常用操作函数-puts、gets、strcmp、strcpy、strcat、strlen
- c语言,strcat(),字符串拼接
- C语言合并字符串函数用法(strcat)