summaryrefslogtreecommitdiff
path: root/whitespace_counter.c
diff options
context:
space:
mode:
Diffstat (limited to 'whitespace_counter.c')
-rw-r--r--whitespace_counter.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/whitespace_counter.c b/whitespace_counter.c
new file mode 100644
index 0000000..ea441e2
--- /dev/null
+++ b/whitespace_counter.c
@@ -0,0 +1,22 @@
+#include<stdio.h>
+
+/*
+ * Count whitespace in input
+ */
+main() {
+ int c, n_whitespace;
+
+ n_whitespace = 0;
+
+ while ((c = getchar()) != EOF) {
+ if (c == '\n')
+ ++n_whitespace;
+ if (c == '\t')
+ ++n_whitespace;
+ if (c == ' ')
+ ++n_whitespace;
+ }
+
+
+ printf("%d\n", n_whitespace);
+}