summaryrefslogtreecommitdiff
path: root/usr.bin/learn/lib/C/L16.2c
diff options
context:
space:
mode:
authorIan Darwin <ian@cvs.openbsd.org>1998-09-28 16:01:29 +0000
committerIan Darwin <ian@cvs.openbsd.org>1998-09-28 16:01:29 +0000
commite9be7faad5fbf61edcad3700142615e315e407bc (patch)
tree5f3febafdfca4e38b83cbc129c87aefdece9ae70 /usr.bin/learn/lib/C/L16.2c
parent0436a5b6c19a613da918536b89a49cbcb38a2e4e (diff)
import BTL learn(1) lessons/C
Diffstat (limited to 'usr.bin/learn/lib/C/L16.2c')
-rw-r--r--usr.bin/learn/lib/C/L16.2c67
1 files changed, 67 insertions, 0 deletions
diff --git a/usr.bin/learn/lib/C/L16.2c b/usr.bin/learn/lib/C/L16.2c
new file mode 100644
index 00000000000..b170a71e838
--- /dev/null
+++ b/usr.bin/learn/lib/C/L16.2c
@@ -0,0 +1,67 @@
+#print
+Write a program to read its input and find the
+word in it with the most vowels (instances of a,e,i,o, or u).
+Print out that word. Compile and test your
+program, then type ready.
+#once #create Ref
+When in the course of human events, it becomes
+necessary for one people to dissolve the political bands which have
+connected them with another, and to assume among the
+powers of the earth the separate and equal station to which
+the laws of Nature and of Nature's God entitle them, a decent
+respect to the opinions of mankind requires that they should
+declare the causes which impel them to the separation.
+ We hold these truths to be self evident, that all men
+are created equal, that they are endowed by their creator
+with certain unalienable rights, that among these are life, liberty,
+and the pursuit of happiness. That to secure these rights,
+governments are instituted among men, deriving their just
+powers from the consent of the governed. That whenever
+any form of government becomes destructive of these ends,
+it is the right of the people to alter or to abolish it, and
+to institute new government, laying its foundation on such
+principles and organizing its powers in such form, as to them
+shall seem most likely to effect their safety and happiness.
+#user
+a.out <Ref >xxx
+grep unalienable xxx >/dev/null
+#succeed
+/* a way to find a word with lots of vowels */
+ #include <stdio.h>
+
+main()
+{
+ char bigword[100], thisword[100];
+ int nvow, maxvow, c, k;
+
+ maxvow = k = 0;
+ while ((c = getchar()) != EOF) {
+ if (c == '\n' || c == ' ') {
+ if (nvow > maxvow) {
+ copy(thisword, bigword, k);
+ maxvow = nvow;
+ }
+ nvow = k = 0;
+ } else {
+ thisword[k++] = c;
+ switch (c) {
+ case 'a': case 'e': case 'i': case 'o': case 'u':
+ nvow++;
+ }
+ }
+ }
+ printf("the word %s had %d vowels\n", bigword, maxvow);
+}
+
+copy(a, b, n)
+char a[], b[];
+{
+ int i;
+
+ for(i = 0; i < n; i++)
+ b[i] = a[i];
+ b[i] = 0;
+}
+#log
+#next
+17.1a 10