Hello everybody i am currently reading 'The C Programming Language' and while i was doing one of the exercises i couldn't solve one of them. The problem no is 1-13. It says
Write a program to print a histogram of the lengths of words in its input. It is easy so draw the histogram with bars horizontal; a vertical orientation is more challenging
So i wrote this code for the first part of the problem, counting:
#include<stdio.h>
int main(void)
{
char c;
int arr[100];
while((c = getchar()) != EOF)
{
int i = 0;
while(c != ' ' || c != '\t' || c != '\n')
{
i++;
c = getchar();
}
arr[i]++;
}
}
but i cannot get it to work, it always get's stuck in seconds while loop. This one:
while(c != ' ' || c != '\t' || c != '\n')
{
i++;
c = getchar();
}
Do you guys have any idea why? I've been staring at this code for 30 minutes now, a similar code worked on earlier exercises but i cannot post the code for them because i deleted them. Sorry if that causes an inconvenience.
I also looked at Print a Histogram based on word lengths (C) but i still don't know why my code doesn't work.
I compile it with gcc main.c
and run it with cat main.c | ./a.out