C 库函数 - strcat()

cpulspuls官方描述—<string.h>

描述:

strcat函数是用来追加字符串的,将一个字符中加到另一个字符中的后面。

声明:

char * strcat ( char * destination, const char * source );

代码实现:

#include <stdio.h>
#include <assert.h>

char* My_strcat(char* to, const char* from)
{
	assert(to && from);
	char* ret = to;

	//找到目标字符串结尾
	while ('\0' != *to)
	{
		to++;
	}
	//copy字符串至目标中
	while (*to++ = *from++)
	{
		;//空
	}
	return ret;
}
int main()
{
	char destination[20] = "This is ";
	char source[20] = "my strcat";

	My_strcat(destination, source);

	printf("%s\n", destination);

	return 0;
}

运行结果:

模拟实现【strcat】函数_库函数