#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
void strdel(char *str,const char* pattern)
{
int len1 = strlen(str);
int len2 = strlen(pattern);
for(int i = 0; str[i] != '\0';i++)
{
int j = 0;
int temp=i;
if(str[i] == pattern[j])
{
while(str[i++] == pattern[j++])
{
if(pattern[j] == '\0')
{
int tmp;
for(tmp=i-len2;str[i] != '\0';i++,tmp++)
{
str[tmp] = str[i];
}
str[i-len2] = '\0';
j=0;
temp--;
break;
}
}
i = temp;
}
}
{
char dst[] = "ababab12abab3456ab";
char pa[] = "ab";
strdel(dst,pa);
cout<<"dst="<<dst<<endl;
}
#include<string.h>
#include<iostream>
using namespace std;
void strdel(char *str,const char* pattern)
{
int len1 = strlen(str);
int len2 = strlen(pattern);
for(int i = 0; str[i] != '\0';i++)
{
int j = 0;
int temp=i;
if(str[i] == pattern[j])
{
while(str[i++] == pattern[j++])
{
if(pattern[j] == '\0')
{
int tmp;
for(tmp=i-len2;str[i] != '\0';i++,tmp++)
{
str[tmp] = str[i];
}
str[i-len2] = '\0';
j=0;
temp--;
break;
}
}
i = temp;
}
}
}
void strdel1(char*str,char*pattern)
{
if(str == NULL || pattern == NULL)
return;
char *src = str;
char *dst = pattern;
int slen = strlen(src);
int dlen = strlen(dst);
int i = 0;
while(src[i] != '\0')
{
int tmp = i;
int j = 0;
if(src[i] == dst[j])
{
while((src[i] == dst[j]) && (src[i] != '\0'))
{
i++;
j++;
}
if(j == dlen)
{
if(src[i] == '\0')
{
src[slen-j] = '\0';
}
else
{
memcpy(&src[i-j],&src[i],slen - i);
src[slen-dlen]='\0';
i = i-j-1;
slen = slen - dlen;
}
}
else
{
i = tmp -1;
}
}
i++;
}
src[slen]='\0';
printf("result=[%s]\n",src);
}
{
char dst[] = "ababab12abab3456ab";
char pa[] = "ab";
strdel(dst,pa);
cout<<"dst="<<dst<<endl;
}