strcpy&memcpy&memmove
2024-09-04 21:13:42
strcpy
extern char *strcpy(char *dest,char *source); { assert((dest!=NULL)&&(source!=NULL)); char *address=dest; while((*dest++=*source++)!='\0'); return address; }
把source所指由NULL结束的字符串复制到dest所指的数组中。source和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳source的字符串。返回指向dest的指针。
memcpy
void *memcpy(void *dest, const void *source, size_t count)//没有对内存重叠进行检查 { assert((dest!=NULL)&&(source!=NULL)); char* tmpDest=(char*)dest; char* tmpSource=(const char*)source; while(count--) *tmpDest++=*tmpSource++; return tmpDest; }
memmove
Copies the values of num bytes from the location pointed by source to the memory block pointed by destination. Copying takes place as if an intermediate buffer were used, allowing the destination and source to overlap
void* memmove(void* dest,const void* src,size_t num) { assert((dest!=NULL)&&(src!=NULL)); char* tmpDest=(char*)dest; char* tmpSrc=(const char*)src; if(src>dest||src+num<dest) { while(num--) *tmpDest++=*tmpSrc++; } else { tmpDest=dest+num-; tmpSrc=src+num-; while(num--) *tmpDest--=*tmpSrc--; } return dest; }
最新文章
- Web性能测试工具JMeter
- JS中NULL和Undefined的区别
- OVER(PARTITION BY)函数介绍
- Java——正则表达式(字符串操作)
- (WF)
- 转:STL使用入门( Using STL)
- jquery 仿购物车的加减数量
- easyUI带复选框的组合树
- C#学习之设计模式:工厂模式
- Python可视化库-Matplotlib使用总结
- 一文搞定MySQL的事务和隔离级别
- C#线程同步--线程通信
- windows安装MongoDB副本集,通过Java程序实现数据的插入与查询
- Matplotlib学习---用matplotlib画折线图(line chart)
- [daily][device][archlinux][trackpoint] 修改指点杆速度/敏捷度
- redis问题:redis-server.exe双击闪退 win10系统
- Mybatis中的缓存
- PhpStorm破解版及使用教程
- ISO27001信息安全管理体系
- SpringBoot(十二)-- 整合Redis