Path: blob/master/languages/cprogs/Ex_1.13.2_His_vertical.c
1240 views
/**1*2* Vertical Histogram of words in a Sentence3*4**/56#include<stdio.h>78#define MAXWL 20 /* Maximum length of a word */9#define MAXNO 25 /* Maximum No of words in a sentence */1011int main(void)12{13int word[MAXNO];14int i, c, j, nc, nw;1516for (i = 0;i < MAXNO; ++i)17word[i] = 0;1819nc = nw = 0;2021while( (c=getchar()) != EOF)22{23++nc;24if( c ==' ' || c =='\n' || c =='\t')25{26/* -1 for excluding the space in the word length */27word[nw] = nc -1;2829++nw;30/* resetting the word-length for the next word */31nc = 0;32}33}3435for( i = MAXWL; i >= 1; --i)36{37for(j=0;j <= nw;++j)38{39if( i <= word[j])40putchar('*');41else42putchar(' ');43}44putchar('\n');45}4647return 0;48}495051