首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >c语言字符串之拼接函数

c语言字符串之拼接函数

作者头像
大忽悠爱学习
发布2021-03-02 15:43:13
发布2021-03-02 15:43:13
1.4K0
举报
文章被收录于专栏:c++与qt学习c++与qt学习

strcat函数:

代码语言:javascript
复制
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
//关于字符串的操作要包含头文件sting.h
#include<string.h>
int main()
{
	//strcat
	char c1[32] = { 0 };
	char c2[32] = { 0 };
	strcat(c1, "hello");
	printf("%s", c1);
	strcat(c2, " world");
	printf("%s\n", c2);
	strcat(c1, c2);
	printf("%s", c1);
	return 0;
}

strncat函数:

代码语言:javascript
复制
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
//关于字符串的操作要包含头文件sting.h
#include<string.h>
int main()
{
	//strncat
	char c1[32] ="hello";
	char c2[32] =" world YES OR NO";
	strncat(c1, c2,6);
	printf("%s", c1);
	strncat(c1, "\nGOODBYE THE WORLD!!!",8);
	printf("\n%s", c1);
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021/02/11 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档