strcpy的实现
来源:互联网 发布:淘宝下载安装最新版 编辑:程序博客网 时间:2024/04/30 11:17
在前面的文章中,我们详细介绍了memcpy函数的实现及其缺陷,本文我们主要介绍下strcpy函数的实现及其与memcpy函数的区别
一样,通过google搜搜strcpy,我们可以得到以下一段话
<cstring>
char * strcpy ( char* destination, const char * source );
Copy string
Copies the C string pointed by source into the arraypointed by destination,including theterminating null character (and stopping at that point).
To avoid overflows, the size of the array pointed by destination shallbe long enough to contain the same C string as source (includingthe terminating null character), andshould not overlapin memory with source.
从以上一段话中,我们可以得到以下几条信息
1、strcpy函数声明变了,不在是void *类型而是char *类型了char * strcpy ( char* destination, const char * source );
2、strcpy不需要指定拷贝字节数,而memcpy需要指定
3、strcpy遇到null字符就结束,而memcpy需要拷贝固定的num个字节,即使中间遇到null也会拷贝
4、和memcpy一样只能进行前向拷贝,而不能进行后向拷贝
strcpy的实现如下所示
char *strcpy(char *dest, const char *src){char *tmp = dest;while ((*dest++ = *src++) != '\0');return tmp;}
- strcpy()库函数的实现
- strcpy函数的实现
- strcpy的实现
- 面试:strcpy的实现
- strcpy()的实现
- strcpy的实现
- strcpy的实现
- strcpy 的实现
- strcpy的实现代码
- strcpy的严格实现
- strcpy的实现代码
- strcpy函数的实现
- strcpy()的简洁实现
- strcpy函数的实现
- strcpy函数的实现
- strcpy的实现
- strcpy的实现
- strcpy函数的实现
- STL中的set容器的一点总结
- 【操作系统】fork()、exec()函数学习笔记
- 向 iOS 设备发送推送通知
- ORACLE将表cache进SGA
- 比较全的JS checkbox全选、取消全选、删除功能代码
- strcpy的实现
- VB学习第九周--计算π的近似值
- 众多Android 开源项目推荐 和分享45个android实例源码,很好很强大
- [4月25日的脚本] 在Office 365 Exchange Online中按类别给任务列表项分类
- linux c语言字符串函数replace,indexOf,substring等的实现
- jQuery 获取屏幕高度、宽度
- Asp.Net直接退出系统的代码!(转)
- Eclipse插件links安装
- C#访问远程主机资源的方法