C语言模拟实现strcpy功能

对于C语言模拟实现strcpy:
1,知道strcpy的功能是:把源地址开始且含有’\0’的字符串拷贝到目标的地址空间去
2,要注意参数的设计,返回值类型的设计,assert的使用,参数部分const的使用
例:
头文件

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

my_strcpy函数部分

char* my_strcpy(char* dest, const char* src)//用char*是为了实现链式访问
{
	char* cp = dest;
	assert(src != NULL);//断言
	assert(dest != NULL);
	while(*cp++ = *src++)
	{
		;
	}
	return dest;	
}

主函数

int main()
{
	char arr[10] = "*********";
	char *str = "abc12345";
	my_strcpy(arr, str);
	printf("%s\n", arr);
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Beer_xiaocai/article/details/84350783