C语言字符中两个字符串拼接(古月)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35061546/article/details/84998721

最忌学习了C语言的基础,深刻的感受到了跨平台语言是多么的强大,我们都是站在了巨人的肩膀上.下面就是C语言将两个字符串拼接起来的代码

#include<stdio.h>

int main(void)
{
	char arr1[] = "hello"; // 定义两个字符数组 C语言中里面没有字符串的概念
	char arr2[] = "world";
	char arrBuf[11]; // 设置字符存放的位置
	int index = 0;   // 字符的索引

	while(arr1[index] != '\0') // 拼接第一个字符数组到目标数组中
	{
		arrBuf[index] = arr1[index];
		index++;
	}

	while(arr2[index - 5] != '\0') // 拼接第二个字符数组到目标数组中
	{
		arrBuf[index] = arr2[index - 5];
		index++;
	}

	arrBuf[index] = '\0'; // 最后拼接字符数组的结束符
	printf("%s\n", arrBuf);
	return 0;
}

这段代码就是在C语言中将两个字符串拼接起来的代码,要是在php中可能就是一个点运算符的事,感谢那些计算机领域前辈付出的努力才有了我们的今天。

猜你喜欢

转载自blog.csdn.net/qq_35061546/article/details/84998721