使用memmove对数组中的指定内容进行删除操作
来源:互联网 发布:av5644769只有我知 编辑:程序博客网 时间:2024/04/30 00:11
#include <iostream>#include <stdlib.h>#include <string.h>using namespace std;int main(){int i,len,cnt;unsigned short t;char *p,*p_end;char buffer[200]; char s[256]="使用memmove函数对数组中指定的内容进行删除操作"; char *q=s; int temp; printf("before delete:\n%s\n\n",s); p=strstr((const char*)s,"memmove");//指向了首地址,即m p_end=strstr((const char*)s,"函数");//结束地址 len = p_end-p;//计算长度 printf("len=%d\r\n",len);temp=p-s;//计算即将删除的内容与数组首地址的偏移量 memmove(s+temp,s+temp+len,strlen(s)+1-len);//把后面的内容往前面移动,实现删除的操作 printf("%s\n",s); //继续删除 “中指定的内容” p=strstr((const char*)s,"中");//指向了首地址,即m p_end=strstr((const char*)s,"进行");//结束地址 len = p_end-p;//计算长度 printf("len=%d\r\n",len);temp=p-s;//计算即将删除的内容与数组首地址的偏移量 memmove(s+temp,s+temp+len,strlen(s)+1-len);//把后面的内容往前面移动,实现删除的操作 printf("%s\n",s); return 0;}
内存移动函数,参数为目标地址,源地址,长度。
注意,这是一个会改变数组内容的函数。
配合strstr使用效果非常好,注意使用strstr定位时,尽量选用唯一的标识。
上述程序执行结果:
0 0
- 使用memmove对数组中的指定内容进行删除操作
- 用TreeSet对指定字符串数组内容进行排序(1)
- 使用splice函数对数组中的元素进行删除时的注意事项
- 使用splice函数对数组中的元素进行删除for循环和for...in的区别
- 手动输入数组中的数据然后对数组进行操作
- 运用fstream对文本文件进行指定读取、删除,指定位置添加一行操作类
- 运用FILE对文本文件进行指定读取、删除,指定位置添加一行操作类
- C#对DataGridView中的数据进行添加、修改、删除操作
- c#对文件夹中的文件进行删除操作
- 删除数组中的指定项
- js对数组进行排序,删除,添加,返回新的数组长度内容
- js中对数组中的数据进行去重操作
- 使用“递归方法”对整个目录进行删除操作
- CaptainGan------ 使用“递归方法”对整个目录进行删除操作
- 在linux中使用open函数对文件进行操作后如何读取文件中的内容 lseek fcntl ioctl
- 使用 delete 删除指定数组
- 对数组进行指定位置的翻转
- 对数组进行各种操作
- 【Oracle】建立索引
- applicationContext.xml文件中class中的内容不能提示
- C#函数
- CSS层模型
- @Transactional(rollbackFor=Exception.class)的作用
- 使用memmove对数组中的指定内容进行删除操作
- 前端动画渲染引擎pixi.js系列(6)副本实现和平铺精灵TilingSprite
- 题目1110:小白鼠排队
- 关于dealloc不执行的原因
- ORA-15038: disk '/dev/mapper/mpath' mismatch on 'Time Stamp' 解决
- 被swoole坑哭的PHP程序员
- [Lpp] PHP的MySQL的操作
- 透明防火墙
- 可重入性和线程安全的关系