]> zdv2.bktei.com Git - BK-2023-05.git/blob - src/kr_exercises/ch1/s1.5/count_btn.c
feat(src/kr/ch1/s1.1/p6):Add hello world example
[BK-2023-05.git] / src / kr_exercises / ch1 / s1.5 / count_btn.c
1 /* Desc: Counts blanks, tabs, and newlines */
2 /* Ref/Attrib: K&R 2nd Ed. Exercise 1-8 */
3
4 #include <stdio.h>
5 int main() {
6 int c, cb, ct, cnl;
7
8 /* Initialize counters */
9 cb = 0;
10 ct = 0;
11 cnl = 0;
12
13 /* User prompt loop. */
14 while((c = getchar()) != EOF) {
15 /* Detect blanks character */
16 if(c == ' ')
17 ++cb;
18
19 /* Detect tab character */
20 if(c == '\t')
21 ++ct;
22
23 /* Detect newline character */
24 if(c == '\n')
25 ++cnl;
26 };
27
28 /* Print results. */
29 printf("Blnk:\t%d\n", cb);
30 printf("Tabs:\t%d\n", ct);
31 printf("Nwln:\t%d\n", cnl);
32 printf("\nDone.\n");
33 };
34
35 /* Author: Steven Baltakatei Sandoval
36 License: GPLv3+ */