summaryrefslogtreecommitdiff
path: root/ch1/counter.c
diff options
context:
space:
mode:
Diffstat (limited to 'ch1/counter.c')
-rw-r--r--ch1/counter.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/ch1/counter.c b/ch1/counter.c
new file mode 100644
index 0000000..a1b9927
--- /dev/null
+++ b/ch1/counter.c
@@ -0,0 +1,29 @@
+#include<stdio.h>
+
+/*
+ * Count characters in input; 1st version
+ */
+//main() {
+// long nc;
+//
+// nc = 0;
+//
+// while (getchar() != EOF)
+// ++nc;
+//
+//
+// printf("%ld\n", nc);
+//}
+
+/*
+ * Count characters in input; 2nd version
+ */
+main() {
+ long nc;
+
+
+ for (nc = 0; getchar() != EOF; ++nc)
+ ;
+
+ printf("%ld\n", nc);
+}