本函数实现的是删除str1中的含有的所有str2 。
char *delstr(char *src, const char *sub)
{
char *st = src, *s1 = NULL;
const char *s2 = NULL;
while (*st&& *sub)
{
s1 = st;
s2 = sub;
while (*s1 && *s2 &&!(*s1 - *s2))
{
s1++;
s2++;
}
if (!*s2)
{
while (*st++=*s1++);
st = src;
}
st++;
}
return (src);
}
int main()
{
char s0[20] = "abcdefg";
char *s1 = "bc";
printf("result:%s\r\n", delstr(s0, s1));
system("pause");
return 0;
}
运行结果: