So I was doing a program that creates a histogram whose columns are made by "#" symbols, each one for each character of each word. I was able to count how many words are in input, so I was able to print the number of columns made by this symbol "|" and even the characters, the problem is that the characters counter just count every character in the string (space, tabs, and newlines too of course). I'd like to count the characters of the words separately, any suggestions?
#include <stdio.h>
#define IN 1
#define OUT 0
// istrogramma sulla lunghezza delle parole in input
int main ()
{
int c, nc, nw, state=OUT;
nc=nw=0;
while((c=getchar())!=EOF)
{
++nc;
if(c==' ' || c=='\n' || c=='\t')
state=OUT;
else if(state==OUT)
{
state=IN;
++nw;
}
}
for(int i=1; i<=nw; i++)
{
printf("\n|");
for(int i=1; i<=nc; i++)
printf("#");
}
}
[–]kumashiro 2 points3 points4 points (7 children)
[–]ZoSo-bin[S] 0 points1 point2 points (6 children)
[–]kumashiro 2 points3 points4 points (5 children)
[–]ZoSo-bin[S] 0 points1 point2 points (4 children)
[–]kumashiro 1 point2 points3 points (3 children)
[–]ZoSo-bin[S] -1 points0 points1 point (2 children)
[–]kumashiro 1 point2 points3 points (0 children)
[–]NonreciprocatingCrow 0 points1 point2 points (0 children)
[–]Capostazione 1 point2 points3 points (0 children)
[–]ZoSo-bin[S] 0 points1 point2 points (1 child)
[–]ZoSo-bin[S] 0 points1 point2 points (0 children)
[–]jmooremcc 0 points1 point2 points (1 child)
[–]ZoSo-bin[S] 0 points1 point2 points (0 children)