summaryrefslogtreecommitdiff
path: root/usr.bin/learn/lib/C/L5.1d
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/learn/lib/C/L5.1d')
-rw-r--r--usr.bin/learn/lib/C/L5.1d48
1 files changed, 48 insertions, 0 deletions
diff --git a/usr.bin/learn/lib/C/L5.1d b/usr.bin/learn/lib/C/L5.1d
new file mode 100644
index 00000000000..bfa7289a452
--- /dev/null
+++ b/usr.bin/learn/lib/C/L5.1d
@@ -0,0 +1,48 @@
+#print
+Write a program that counts the blanks, tabs, and newlines
+in its input, and prints the total. Don't forget to
+define the value of EOF at the beginning of your program.
+The best way is to add
+
+ #include <stdio.h>
+
+as the first line of your program.
+The must____ be in column 1.
+(See page 143 of the C book.)
+You may also have to say
+
+cc name.c -lS
+
+to compile the program.
+#once #create Ref
+This is some junk that
+contains
+ blanks
+ tabs
+ and newlines.
+#user
+a.out <Ref >test1
+a.out </dev/null >test2
+grep 13 test1 >/dev/null && grep 0 test2 >/dev/null
+#succeed
+One possible solution:
+
+ #include <stdio.h>
+
+main()
+{
+ int n, c;
+
+ n = 0;
+ while ((c = getchar()) != EOF)
+ if (c == ' ' || c == '\t' || c == '\n')
+ n++;
+ printf("%d\n", n);
+}
+
+This program won't work on huge files, because an int
+isn't big enough.
+#log
+#next
+5.1e 10
+5.2e 5