aboutsummaryrefslogtreecommitdiff
path: root/ch2/2-04_squeeze-v2.c
diff options
context:
space:
mode:
authorzlg <zlg@zlg.space>2016-06-16 10:15:33 -0700
committerzlg <zlg@zlg.space>2016-06-16 10:15:33 -0700
commitf8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7 (patch)
treee37b327d7f93435e93a57427600d2b91fbb0cd87 /ch2/2-04_squeeze-v2.c
parentSolve Exercise 7-2: Format arbitrary input (diff)
downloadknr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.tar.gz
knr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.tar.bz2
knr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.tar.xz
knr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.zip
The massive astyle sweep!
Code style should be consistent now. All future commits will be run through astyle or they will be amended.
Diffstat (limited to 'ch2/2-04_squeeze-v2.c')
-rw-r--r--ch2/2-04_squeeze-v2.c13
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;
}