代码改变世界

有趣的字符串copy函数

2022-09-11 11:13  钟铧若岩  阅读(24)  评论(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 }