库函数学习(1):简单实现strcpy
来源:互联网 发布:必向东java 编辑:程序博客网 时间:2024/06/06 03:44
这里先附上我的实现以及测试代码。
该实现是经典实现,网络与库函数源码都能找到。
#include <stdio.h>#include <string.h>//#define NDEBUG#include <assert.h>#ifndef NULL //防止NULL没有定义,一般NULL不会没有定义,但作为库函数还是严谨点好。 #define NULL (void *)0#endifchar *mystrcpy(char *dest, const char *src){ assert(dest != NULL && src != NULL); //断言:在库函数实现中并没有空指针判断。如果你是做面试题请写上,如果你是做项目,请结合项目需求,平衡性能与安全。 char *cp = dest; //保存返回地址,这个很重要 while ((*dest++ = *src++) != '\0') //最核心的语句,慢慢体会吧,库函数中还有更厉害的实现,不过理解这个已经够了。 ; return cp;}int main(void){ char hello[]="hello world!"; char test[]="hello boy!"; char dest[32] = {0}; mystrcpy(dest, hello); printf("mystrcpy dest: %s\n", dest); strcpy(dest, test); printf("strcpy dest: %s\n", dest); return 0;}
0 0
- 库函数学习(1):简单实现strcpy
- strcpy()库函数的实现
- 不用库函数实现strcpy
- 实现库函数strcpy
- 实现库函数strcpy
- 库函数strcpy的实现
- 实现C库函数strcpy
- 模拟实现库函数Strcpy
- strcpy 库函数 实现
- 模拟实现库函数strcpy
- strcpy库函数的实现。。
- 模拟实现库函数strcpy
- 高效面试之实现strcpy等简单库函数
- 库函数strcpy的实现讨论
- C库函数—strcpy实现
- C库函数—strcpy实现
- C++库函数strcpy的实现
- 不调用库函数,实现strcpy
- zoj 3810
- Linux MySQL操作
- Struts2中过滤器,拦截器,监听器他们之间有什么区...
- Java Memory Usage
- extjs Combobox动态加载数据问题,mode:local 还是remote
- 库函数学习(1):简单实现strcpy
- Angularjs 第五章 读书笔记
- 1159 Palindrome(最少插入回文串)
- Web项目管理工具精选
- VC++ 安装驱动 详细解释
- SQL Server中的Collate排序规则关键字的使用
- Java compiler level does not match the version of the installed Java 及MyEclipse中没有ProjectFacets
- ORA-00936 缺失表达式
- 色纺二十个认同感人的很多人挺好他与和大统华太阳花太费劲