|
发表于 2021-1-29 16:07:56
|
显示全部楼层
上面那个确实有问题
- #include "stdio.h"
- #include "stdlib.h"
- #include "string.h"
- void delet(char *s1,char *s2);
- int main()
- {
- char s1[80],s2[80];
- printf("请输入一个字符串\n");
- scanf("%s",s1);
- printf("请输入一个要删除的子串\n");
- scanf("%s",s2);
- delet(s1,s2);
- }
- void delet(char *s1,char *s2){
- char *p1,*p2,result[80]={'\0'};
- p2=s1;
- while((p1=strstr(s1,s2))!=NULL)
- {
- strncat(result,s1,p1-p2);
- strcpy(s1,p1+strlen(s2));
- p2=s1;
- }
- strcat(result,s1);
- printf("%s\n",result);
- }
复制代码
这个可以,出自https://blog.csdn.net/z2541498852/article/details/78841167
运行结果:
- 请输入一个字符串
- qwerdf1234qw
- 请输入一个要删除的子串
- qw
- erdf1234
- --------------------------------
- Process exited after 15.69 seconds with return value 0
- 请按任意键继续. . .
复制代码 |
|