summaryrefslogtreecommitdiff
path: root/usr.bin/learn/lib/C/L16.2c
blob: b170a71e838549ab7e670a97615e37600b4c7df6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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