diff options
Diffstat (limited to '')
-rw-r--r-- | ch2/2-04_squeeze-v2.c | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/ch2/2-04_squeeze-v2.c b/ch2/2-04_squeeze-v2.c index 2c3b56a..7a49585 100644 --- a/ch2/2-04_squeeze-v2.c +++ b/ch2/2-04_squeeze-v2.c @@ -16,13 +16,12 @@ * */ -// It'd be better to make this return a pointer (or string), but the book -// hasn't covered it yet! +/* It'd be better to make this return a pointer (or string), but the book */ +/* hasn't covered it yet! */ void squeeze(char s1[], char s2[]) { int i, j, k, match; - for (i = j = 0; s1[i] != '\0'; i++) { - // I don't see a way to do this without a flag + /* I don't see a way to do this without a flag */ match = 0; for (k = 0; s2[k] != '\0'; k++) { if (s1[i] == s2[k]) { @@ -30,22 +29,18 @@ void squeeze(char s1[], char s2[]) { break; } } - // check our flag. if there wasn't a match, j needs to match i's value + /* check our flag. if there wasn't a match, j needs to match i's value */ if (!match) { s1[j++] = s1[i]; } } - s1[j] = '\0'; } int main() { char foo[16] = "foobarbaz"; char bar[16] = "boz"; - squeeze(foo, bar); - printf("%s\n", foo); // Should read "fara" - return 0; } |