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); }