C语言之memmove函数
来源:互联网 发布:类似youcam的软件 编辑:程序博客网 时间:2024/06/05 15:57
【FROM MSDN && 百科】
原型: void *memmove( void* dest, const void* src, size_tcount );
#include<string.h>
由src所指内存区域复制count个字节到dest所指内存区域。
src和dest所指内存区域可以重叠,但复制后dest内容会被更改。函数返回指向dest的指针。
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.
memmove的处理措施:
(1)当源内存的首地址等于目标内存的首地址时,不进行任何拷贝
(2)当源内存的首地址大于目标内存的首地址时,实行正向拷贝
(3)当源内存的首地址小于目标内存的首地址时,实行反向拷贝
DEMO:
//#define FIRST_DEMO//#define SECOND_DEMO#define MYMEMMOVE#ifdef FIRST_DEMO#include <stdio.h>#include <conio.h>#include <string.h>int main(void){char s[]="Golden Global View";memmove(s,s+7,strlen(s)+1-7);//+1是取'\0',可以去掉看下结果printf("%s\n",s);getch();return 0;}#elif defined SECOND_DEMO#include <stdio.h>#include <conio.h>#include <string.h>int main(void){char str1[7]="aabbcc";printf( "The string: %s\n", str1 );memcpy(str1+2,str1,4);printf( "New string: %s\n", str1 );memmove(str1+2,str1,4);printf( "New string: %s\n", str1 );getch();return 0;}/*output:The string: aabbccNew string: aaaabbNew string: aaaaaa*/#elif defined MYMEMMOVE#include <stdio.h>#include <conio.h>#include <string.h>#include <assert.h>void *mymemmove(void *dest,const void *src,size_t coount);int main(void){ char str1[7]="aabbcc"; mymemmove(str1+2,str1,4);puts(str1);getch();return 0;}void *mymemmove(void *dest,const void *src,size_t count){char *ret=(char *)dest;char *dest_t=dest;char *src_t=(char *)src;assert( NULL !=src && NULL !=dest);if (dest_t<=src_t || dest_t>=src_t+count){ while(count--){*dest_t++ = *src_t++;}}else{dest_t+=count-1;src_t+=count-1;while(count--){*dest_t--=*src_t--;}}return ret;}#endif
- C语言之memmove函数
- C语言之memmove函数
- C语言memmove函数
- C语言函数_string.h 之 内存copy函数memmove
- 用C语言实现memmove函数
- 用C语言实现函数 memmove
- 【C语言】实现memcopy、memmove函数
- C语言模拟实现memcpy,memmove函数
- 【c语言】模拟实现memcpy()、memmove()函数
- C语言 memcpy memmove
- 【C语言】 实现memmove
- 【题目12】用C语言实现memmove函数
- 细谈C语言中的strcpy,strncpy,memcpy,memmove,memset函数
- 细谈C语言中的strcpy,strncpy,memcpy,memmove,memset函数
- 细谈C语言中的strcpy,strncpy,memcpy,memmove,memset函数
- 细谈C语言中的strcpy,strncpy,memcpy,memmove,memset函数
- 细谈C语言中的strcpy,strncpy,memcpy,memmove,memset函数 .
- 细谈C语言中的strcpy,strncpy,memcpy,memmove,memset函数
- 38_日志工具commons-logging与Log4J
- Hive Job log解析——perl脚本
- shell相关概念
- 遍历文件夹windows
- 原子性
- C语言之memmove函数
- Apache Felix
- linux man命令加数字
- Android 的消息队列模型
- 在后台运行Python脚本服务
- Shell 脚本简介
- C#水晶报表教程
- linux select()函数
- Linux练习题