-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-13.c
67 lines (55 loc) · 1.64 KB
/
1-13.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
write histogramme of the lengh of words in its input
*/
#include <stdio.h>
#define VLINE 100 /* to be print out "|" */
#define NEXT__VLINE 50 /* to be print out " " once then "|" after that*/
int main(){
int i, k, l, m, c, wc, maxvalue;
k = c = wc = l = m = maxvalue = 0;
int arr [20];
for (i = 0 ; i < 20; i++){
arr[i] = 0;
}
while ((c = getchar()) != EOF){
// count any input
++wc;
// prepare array for printing histograme
if (c == ' ' | c == '\n' | c == '\t' ){
--wc;
if (wc != 0){
++arr [wc * 2];
k = arr [wc * 2];
if (maxvalue < k){
maxvalue = k;
}
wc = 0;
}
}
}
printf ("this is maxvalue %d \n", maxvalue);
for (m = maxvalue; m >= 0; --m){
for (l = 0; l < 20; ++l){
if (arr[l] == VLINE ){
printf ("|");
}
else if (arr[l] == NEXT__VLINE ){
printf (" ");
arr[l] = VLINE;
}
else if (arr[l] == m && m != 0 ){
printf ("_");
if (arr [l - 1] == 0){
arr [l - 1] = VLINE;
}
if (arr [l + 1] == 0){
arr [l + 1] = NEXT__VLINE;
}
}
else{
printf (" ");
}
}
printf ("\n");
}
}