C语言:strcpy

char *strcpy(char *restict dst,const char *restrict src);dst是目的,src是原

这会把src的字符串拷贝到dst

restrict表示src和dst不重叠

返回dst

char *dst=(char*)malloc(strlen(src)+1);

strcpy(dst,src);

#include <stdio.h>

#include <string.h>

char* mycpy(char* dst,const char* src)

{

//int idx = 0;

//while(srcidx){

//dstidx=srcidx;

//idx++;

//}

//dstidx = '\0';

char*ret = dst;

while(*src !='\0'){

*dst = *src;

dst++;

src++;

}

*dst ='\0';

return ret;

}

int main(int argc,char const *argv\[\])

{

char s1\[\] = "abc";

char s2\[\] = "abc";

mycpy(s1,s2);

printf("%d %d",s1,s2);

return 0;

}

相关推荐
江华森3 分钟前
04-python-面向对象
开发语言·python
AI行业学习6 分钟前
Notepad++ 官方纯净下载+完整安装教程(Windows)【2026.7.5】
开发语言·windows·python·前端框架·html·notepad++
前端百草阁19 分钟前
JavaScript 设计模式(23 种)
开发语言·前端·javascript·设计模式
EntyIU23 分钟前
Java NIO 实战
java·开发语言·nio
浩瀚之水_csdn44 分钟前
Python 3 网络编程详解:从原理到实战
开发语言·网络·python
geovindu1 小时前
java: Singleton Pattern
java·开发语言·后端·单例模式·设计模式·创建型模式
AI行业学习1 小时前
2026 版 Notepad++ 完整图文安装指南|官方渠道无捆绑,一键切换中文界面
开发语言·人工智能·python·html·notepad++
鹏易灵1 小时前
C++——7.类与对象,掌握封装、继承、多态.详解
开发语言·c++·算法
水无痕simon1 小时前
5 多表操作
java·开发语言·数据库
初阳7851 小时前
【Qt】系统相关(2)——文件
开发语言·qt