summaryrefslogtreecommitdiffstats
path: root/1/8.c
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-11-16 19:42:38 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-11-16 19:42:38 +0800
commit49a03e32c1f419e98c8886d46c438b3efa859947 (patch)
tree36be79ac1787a3f500d5e609f7740344ba30cc57 /1/8.c
parent3c3f71ceb83e6f8317ba55244f06f67c107e5c51 (diff)
downloadk&r-exercises-49a03e32c1f419e98c8886d46c438b3efa859947.tar.gz
1.8
Diffstat (limited to '1/8.c')
-rw-r--r--1/8.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/1/8.c b/1/8.c
new file mode 100644
index 0000000..400a2de
--- /dev/null
+++ b/1/8.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+/* counts blanks, tabs and newlines in input */
+int main(int argc, char *argv[]) {
+ int c, bc, tc, nc;
+
+ bc = tc = nc = 0;
+
+ while ((c = getchar()) != EOF) {
+ if (c == ' ')
+ bc++;
+ else if (c == '\t')
+ tc++;
+ else if (c == '\n')
+ nc++;
+ }
+
+ printf("blanks: %d, tabs: %d, newlines: %d\n", bc, tc, nc);
+ return 0;
+} \ No newline at end of file