Skip to content

Commit d066343

Browse files
authored
Take the last word in accoun.
In the current version of the solution last word was omitted if it was followed be EOF. This input q q q qq qq qqq qqq produces Horizontal Histogram -------------------- 1: ### 2: ## 3: # but should be Horizontal Histogram -------------------- 1: ### 2: ## 3: ##
1 parent 5fd36ec commit d066343

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

chapter_1/exercise_1_13/histogram.c

Lines changed: 3 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,7 @@ int main(void)
4343

4444
word_count_index = 0;
4545
}
46+
if (c == EOF) break;
4647
}
4748
else
4849
{

0 commit comments

Comments
 (0)