c语言找到一个字符串数组包含于另一个数组

c语言找到一个字符串数组包含的另一个数组 并剔除
比如一个数组是{abc}另一个是{babcd} 在{babcd}中把{abc}剔除 最后成为 {bd}

void remove(char* str, char *substr)
{
int l = strlen(substr);
char* s = str;
int i;
while (*s)
{
if (memcmp(s, substr, l) == 0)
{
memset(s, 0, l);
s += l;
}
else
{
s++;
}
}
i = s - str;
s = str;
while (i)
{
*s = *str;
if (*str != 0) s++;
str++;
i--;
}
*s = 0;
}
int main()
{
char a[] = "adabcddabcdd";
char b[] = "abc";
remove(a, b);
printf("%s", a);
getch();
return 0;
}

温馨提示:答案为网友推荐,仅供参考
相似回答