Skip to content

Commit

Permalink
Fixing implementations.
Browse files Browse the repository at this point in the history
  • Loading branch information
janpgit committed Mar 3, 2024
1 parent 91992f2 commit a54ff76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/words.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions src/words2.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ main(void)
inword = 1;
}

if (inword == 1)
++words;

printf("%d\n", words);
}

0 comments on commit a54ff76

Please sign in to comment.