zhiye_wang

向星空仰望的越深,越发现自己的渺小

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  31 随笔 :: 1 文章 :: 2 评论 :: 0 Trackbacks
 1 #include "stdafx.h"
 2 #include "iostream"
 3 #include "assert.h"
 4 
 5 using namespace std;
 6 
 7 char* mystrcpy(char* dest, const char* src); // 1 const
 8 
 9 
10 int main(int argc, char* argv[])
11 {
12     printf("Hello World!\n");
13     char buf[10] = {0};
14     mystrcpy(buf, "FUCK!");
15     cout << buf << endl;
16     return 0;
17 }
18 
19 char* mystrcpy(char* dest, const char* src)
20 {
21     assert(dest!=NULL && src!=NULL);   // 2 assert
22     char* p = dest;
23     while (*p++ = *src++);
24     *p = '\0';                                    // 3 字符串结束
25     return dest;
26 }

输出:
Hello World!
FUCK!
Press any key to continue
posted on 2014-06-12 09:11 zhiye_wang 阅读(171) 评论(0)  编辑 收藏 引用 所属分类: C/C++通用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理