【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)当源内存的首地址小于目标内存的首地址时,实行反向拷贝

//#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: aabbcc
New string: aaaabb
New 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

  

最新文章

  1. 关押罪犯 and 食物链(并查集)
  2. 解决 Error: getaddrinfo EADDRINFO 错误
  3. Bootstrap3系列:下拉菜单
  4. SerializableDictionary-一个支持序列化与反序列化的Dictionary
  5. Surface、SurfaceView、SurfaceHolder及SurfaceHolder.Callback之间的关系
  6. Refresh recovery area usage data after manually deleting files under recovery area
  7. php图片转为资源数据
  8. 构建移动Web应用程序的技术堆栈
  9. jQuery无刷新上传学习心得
  10. C++11多线程
  11. PhpStorm11.0 配置在浏览器中打开文件
  12. Android图表库MPAndroidChart(五)——自定义MarkerView实现选中高亮
  13. Android存储系统的架构与设计
  14. 从输入一个URL到页面完全显示发生了什么?
  15. C++ 模板基础
  16. -bash: yum: command not found
  17. appium+robotframework常见技巧总结
  18. JavaScript--浅谈!=、!==、==和===的区别
  19. QT中PRO文件写法的详细介绍
  20. spring mvc项目中导出excel表格简单实现

热门文章

  1. Ganglia监控搭建
  2. C字符数组及其应用
  3. HDOJ 2055 An easy problem
  4. python 解析xml 文件: Element Tree 方式
  5. lyGrid表格插件
  6. keil中for循环变量递减,无法跳出循环的问题
  7. easyUI属性总结
  8. Python算法之---冒泡,选择,插入排序算法
  9. MySQL更新时Error Code:1093和Error Code:1175的解决办法
  10. [Angular 2] NgNonBindable