C语言:写一个函数模拟实现strcpy()

cs 复制代码
#include<stdio.h>
#include<assert.h>
char* my_strcpy(char* dest, const char* src) {
	assert(src);
	assert(dest);
	char* ret = dest;
	while (*src) {
		*dest++ = *src++;
	}
	*dest = *src;
	return ret;
}
int main() {
	char arr1[] = "abcdef";
	char arr2[20] = { 0 };
	my_strcpy(arr2, arr1);
	printf("%s\n", arr2);
	return 0;
}

运行结果

相关推荐
淡忘旧梦19 小时前
词错误率/WER算法讲解
人工智能·笔记·python·深度学习·算法
冬奇Lab19 小时前
【Kotlin系列11】协程原理与实战(下):Flow与Channel驯服异步数据流
android·开发语言·kotlin
Jia shuheng19 小时前
#ifdef __cplusplus extern “C“ #endif的作用
c语言·嵌入式硬件
好大哥呀19 小时前
如何在手机上运行Python程序
开发语言·python·智能手机
阿蒙Amon19 小时前
C#每日面试题-is和as的区别
java·开发语言·c#
狐5719 小时前
2026-01-21-牛客每日一题-静态区间和(前缀和)
笔记·算法
毕设源码-钟学长19 小时前
【开题答辩全过程】以 基于Python的新闻热点舆情分析系统为例,包含答辩的问题和答案
开发语言·python
2401_8414956419 小时前
【Python高级编程】单词统计与查找分析工具
数据结构·python·算法·gui·排序·单词统计·查找
XerCis19 小时前
Python代码检查与格式化工具Ruff
开发语言·python
少控科技19 小时前
QT高阶日记010
开发语言·qt