From a54ff76d736d0241c23fc00bc321c391c1afa9c6 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 3 Mar 2024 22:31:52 +0100 Subject: [PATCH] Fixing implementations. --- src/words.c | 10 +++++++--- src/words2.c | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/words.c b/src/words.c index 846ac64c..3b6820c5 100644 --- a/src/words.c +++ b/src/words.c @@ -10,15 +10,19 @@ main(void) while ((c = getchar()) != EOF) { /* Use library function (hence the ctype.h include above) */ - if (!isspace(c)) - word = 1; - else { + if (isspace(c)) { if (word == 1) { cnt++; word = 0; } + } else { + word = 1; } } + /* No newline at the end of input. */ + if (word) + ++cnt; + printf("cnt = %d\n", cnt); } diff --git a/src/words2.c b/src/words2.c index 488a4ce6..6191e241 100644 --- a/src/words2.c +++ b/src/words2.c @@ -14,5 +14,8 @@ main(void) inword = 1; } + if (inword == 1) + ++words; + printf("%d\n", words); }