aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzlg <zlg@zlg.space>2013-02-08 03:51:59 -0600
committerzlg <zlg@zlg.space>2013-02-08 03:51:59 -0600
commit4ab3e04fd11d9476fac12db5f65cdd0d5a7b8772 (patch)
tree721b0933040a011b2bed9f5f74ac47e4ca15dbe1
parentSolve Exercises 1-1 to 1-12 (diff)
downloadknr-4ab3e04fd11d9476fac12db5f65cdd0d5a7b8772.tar.gz
knr-4ab3e04fd11d9476fac12db5f65cdd0d5a7b8772.tar.bz2
knr-4ab3e04fd11d9476fac12db5f65cdd0d5a7b8772.tar.xz
knr-4ab3e04fd11d9476fac12db5f65cdd0d5a7b8772.zip
Fix Exercise 1-12's solution
Printing a newline for each whitespace character was the wrong behavior.
-rw-r--r--1-12_one-word-per-line.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/1-12_one-word-per-line.c b/1-12_one-word-per-line.c
index 3f31d1d..29a38df 100644
--- a/1-12_one-word-per-line.c
+++ b/1-12_one-word-per-line.c
@@ -22,8 +22,10 @@ int main(void) {
nl++;
}
if (c == ' ' || c == '\n' || c == '\t') {
- state = OUT;
- putchar('\n');
+ if (state == IN) {
+ state = OUT;
+ putchar('\n');
+ }
} else if (state == OUT) {
state = IN;
nw++;