summaryrefslogtreecommitdiff
path: root/ch2/2-04.c
blob: 3f122bbd9475a10a319703806176772515c2c57d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>


void squeeze_char(char s[], char c) {
    int i;
    int j;

    for (i = j = 0; s[i] != '\0'; i++)
        if (s[i] != c)
            s[j++] = s[i];

    s[j] = '\0';
}


void squeeze_str(char s1[], char s2[]) {
    int i;

    for (i = 0; s2[i] != '\0'; ++i)
        squeeze_char(s1, s2[i]);
}


void squeeze_all(char s1[], char s2[]) {
    int i;
    int j;
    int k;

    for (k = 0; s2[k] != '\0'; ++k) {
        for (i = j = 0; s1[i] != '\0'; ++i)
            if (s1[i] != s2[k])
                s1[j++] = s1[i];

        s1[j] = '\0';
    }
}


int main() {
    char squeezed[] = "abracadabra";
    squeeze_all(squeezed,"abc");
    printf("%s\n", squeezed);
}