Skip to content

Commit a24dc20

Browse files
authored
Merge pull request #47 from Shakenbeer/patch-1
Take the last word in accoun.
2 parents f78b1fd + 988e08b commit a24dc20

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

chapter_1/exercise_1_13/histogram.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ int main(void)
2323
// specific index
2424
char c;
2525
int word_count_index = 0;
26-
while ((c = getchar()) != EOF)
26+
while (c = getchar())
2727
{
28-
if (c == ' ' || c == '\t' || c == '\n')
28+
if (c == ' ' || c == '\t' || c == '\n' || c == EOF)
2929
{
3030
if (word_count_index > 0)
3131
{
@@ -43,6 +43,10 @@ int main(void)
4343

4444
word_count_index = 0;
4545
}
46+
if (c == EOF)
47+
{
48+
break;
49+
}
4650
}
4751
else
4852
{

0 commit comments

Comments
 (0)