summaryrefslogtreecommitdiff
path: root/counter.c
diff options
context:
space:
mode:
authorAdam Carpenter <53hornet@gmail.com>2019-05-10 16:00:12 -0400
committerAdam Carpenter <53hornet@gmail.com>2019-05-10 16:00:12 -0400
commit2c345e0909a082b77be959a4e6166cdbdc79e067 (patch)
tree4d9ff5a2884e5b87b8c0cb8e7fa358e3a9625eb4 /counter.c
downloadlearning-c-2c345e0909a082b77be959a4e6166cdbdc79e067.tar.xz
learning-c-2c345e0909a082b77be959a4e6166cdbdc79e067.zip
Init.
Diffstat (limited to 'counter.c')
-rw-r--r--counter.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/counter.c b/counter.c
new file mode 100644
index 0000000..a1b9927
--- /dev/null
+++ b/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);
+}