Remove mkc.sh; change README.md to reflect this
[copyleftie-krc.git] / ch01 / ex01-13.c
bloba900fd0a0cefa9f67c9804990f9925a9e1e9fed2
1 #!/usr/bin/tcc -run
2 #include <stdio.h>
4 #define MAXLENGTH 16 /* It is very rare for a word to be so long. */
5 #define IN 1
6 #define OUT 0
8 int
9 main() {
10 int c, i, length, state;
11 int nlength[MAXLENGTH]; /* nlength[0] is for words of length 1. */
13 for (i = 0; i < MAXLENGTH; ++(i))
14 nlength[i] = 0;
16 state = OUT;
17 length = 0;
18 while ((c = getchar()) != EOF) {
19 if (!((c >= '0' && c <= '9')
20 || (c >= 'a' && c <= 'z')
21 || (c >= 'A' && c <= 'Z'))) {
22 if (state == IN) {
23 state = OUT;
24 if (length > 0) {
25 ++(nlength[length-1]);
26 length = 0;
28 } /* else, noop */
29 } else {
30 if (length < MAXLENGTH)
31 ++(length);
32 if (state == OUT)
33 state = IN;
37 for (i = 0; i < MAXLENGTH; ++(i)) {
38 printf("%2d ", i+1);
39 for (c = 0; c < nlength[i]; ++(c))
40 putchar('*');
41 putchar('\n');
44 return 0;