/home/toolbox/public_html/solutions/100/10062/b.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15
16 /*
17 * Author: Isaac Traxler
18 * Date: 2017-09-27
19 * Purpose: fun
20 * Problem: 10062 - Tell me the frequencies!
21 */
22
23 /*
24 * This template reads lines of data at a time until end of file.
25 */
26
27 #define MAX_LINE 1024
28
29
30 char line[MAX_LINE];
31 int cnt[128];
32
33 void init()
34 {
35 /* FUNCTION init */
36 int i;
37
38 for (i=32; 128>i; i++)
39 {
40 cnt[i] = 0;
41 }
42 } /* FUNCTION init */
43
44 void dump()
45 {
46 /* FUNCTION dump */
47 } /* FUNCTION dump */
48
49 int getInput()
50 {
51 /* FUNCTION getInput */
52 int dataReadFlag;
53
54 fgets(line, MAX_LINE, stdin);
55 if (feof(stdin))
56 dataReadFlag = FALSE;
57 else
58 {
59 /* something to read */
60 dataReadFlag = TRUE;
61 line[strlen(line)-1] = 0;
62 } /* something to read */
63 return (dataReadFlag);
64 } /* FUNCTION getInput */
65
66 void process()
67 {
68 /* FUNCTION process */
69 int i;
70
71 init(); /* reset counts */
72 /* process seach char -- incrementing counter in array */
73 for (i=0; strlen(line)>i; i++)
74 {
75 /* for each character in the line */
76 cnt[line[i]]++;
77 } /* for each character in the line */
78 /* process each count and dump out non-zero ones */
79 for (i=28; 128>i; i++)
80 {
81 /* for each counter */
82 if (0 < cnt[i])
83 {
84 printf("%d %d\n", i, cnt[i]);
85 }
86 } /* for each counter */
87 } /* FUNCTION process */
88
89 int main()
90 {
91 /* main */
92 int moreToDo;
93
94 moreToDo = getInput();
95 while (moreToDo)
96 {
97 /* while */
98 process();
99 moreToDo = getInput();
100 if (moreToDo)
101 {
102 printf("\n");
103 }
104 } /* while */
105
106 return EXIT_SUCCESS;
107 } /* main */
108