练习2-4 重新编写函数 squeeze

重新编写函数 squeeze(s1,s2),将字符串 s1 中任何与字符串 s2 中字符匹配的字符都删除

//原函数
void squeeze(char s[], int c) {
    int i, j;
    for (i = j = 0; s[i] != '\0'; i++) {
        if (s[i] != c) {
            s[j++] = s[i];
        }
    }
    s[j] = '\0';
}
//重写
void squeeze(char s1[], char s2[]) {
    int i;
    for (i = 0; s2[i] != '\0'; i++) {
        int b,j;
        for (b =j= 0; s1[b] != '\0';b++) {
            if (s1[b] != s2[i]) {
                s1[j++] = s1[b];
            }
        }
        s1[j] = '\0';
    }
}
//使用
char s1[] = "abcgsdgewgwegrwerd";
char s2[] = "bdg";
squeeze(s1,s2);
printf("s1 结果 %s \n", s1);
//输出:s1 结果 acsewwerwer