代码改变世界

有趣的字符串copy函数

  钟铧若岩  阅读(31)  评论(0编辑  收藏  举报
复制代码
 1 #include <iostream>
 2 #include <iomanip>
 3 #include <string>
 4 using namespace std;
 5 double power(double x,int n);
 6 char * mycopy(char *dest, const char * src)
 7 {
 8     if(src == NULL || dest ==NULL)
 9         return NULL;
10     if(src == dest)
11         return NULL;
12     char *temp = dest;
13     cout << "src = " << src << endl;
14     while((*dest++ = *src++)!= '\0'){}
15     
16     cout <<"temp = "<<temp<<endl;
17     
18     return temp;
19 }
20 
21 int main()
22 {
23     cout <<"hello"<<endl;
24     
25     char src[10] = "wfg";
26     char dest[10];
27     mycopy(dest,src);
28     cout << "dest = "<< dest <<endl;
29     return 0;
30     
31 }
复制代码

 

相关博文:
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示