Added stack address randomization example.
[C-Programming-Examples.git] / ex_1-13.c
blobbbf0fbe24d72adeff813c9ebe8fbfed544221e8a
1 #include <stdio.h>
3 main()
5 int c, i, j, nwhite, nother, maxnum;
6 int ndigit[10];
8 maxnum = 0;
9 nwhite = nother = 0;
10 for(i = 0; i < 10; i++)
11 ndigit[i] = 0;
13 while ((c = getchar()) != EOF)
14 if(c >= '0' && c <= '9')
15 ++ndigit[c-'0'];
16 else if (c == ' ' || c == '\n' || c == '\t')
17 ++nwhite;
18 else
19 ++nother;
21 /* print out histogram */
23 for(i = 0; i <= 10; ++i)
25 if(ndigit[i] > maxnum) { maxnum = ndigit[i]; }
28 for(i = 0; i < maxnum; ++i) // one row for each instance of number
30 printf("%d\t|", maxnum-i); // print sidebar
31 for(j = 0; j <= 10; ++j) // one column for each number
33 if(ndigit[j] >= maxnum-i) { putchar('*'); } else { putchar(' '); }
35 printf("\n");
38 printf("\t 0123456789\n");