Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/cprogs/Ex_1.13.2_His_vertical.c
1240 views
1
/**
2
*
3
* Vertical Histogram of words in a Sentence
4
*
5
**/
6
7
#include<stdio.h>
8
9
#define MAXWL 20 /* Maximum length of a word */
10
#define MAXNO 25 /* Maximum No of words in a sentence */
11
12
int main(void)
13
{
14
int word[MAXNO];
15
int i, c, j, nc, nw;
16
17
for (i = 0;i < MAXNO; ++i)
18
word[i] = 0;
19
20
nc = nw = 0;
21
22
while( (c=getchar()) != EOF)
23
{
24
++nc;
25
if( c ==' ' || c =='\n' || c =='\t')
26
{
27
/* -1 for excluding the space in the word length */
28
word[nw] = nc -1;
29
30
++nw;
31
/* resetting the word-length for the next word */
32
nc = 0;
33
}
34
}
35
36
for( i = MAXWL; i >= 1; --i)
37
{
38
for(j=0;j <= nw;++j)
39
{
40
if( i <= word[j])
41
putchar('*');
42
else
43
putchar(' ');
44
}
45
putchar('\n');
46
}
47
48
return 0;
49
}
50
51