From 4ab3e04fd11d9476fac12db5f65cdd0d5a7b8772 Mon Sep 17 00:00:00 2001 From: zlg Date: Fri, 8 Feb 2013 03:51:59 -0600 Subject: Fix Exercise 1-12's solution Printing a newline for each whitespace character was the wrong behavior. --- 1-12_one-word-per-line.c | 6 ++++-- 1 file 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++; -- cgit v1.2.3-70-g09d2 ' name='id' value='41d86a29051af9e3b5fe7e37bd4c0c0a18993767'/> Category-0 solutions to The C Programming Language, 2nd Editionzlg
aboutsummaryrefslogtreecommitdiff
path: root/ch2/2-06_setbits.c (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-01-09Refactor syscalls.h for ch8 exerciseszlg3-117/+234
2018-12-22Solve Exercise 8-2: fopen and fillbufzlg3-0/+181
2018-08-22AUTHORS: update contact infozlg1-1/+1
2017-05-20perfeeerrrrrmzlg1-1/+1
2017-05-208-1: Correct superfluous increment, commentzlg1-2/+1