Annotation of 43BSD/usr.lib/learn/C/L16.2c, revision 1.1.1.1

1.1       root        1: #print
                      2: Write a program to read its input and find the
                      3: word in it with the most vowels (instances of a,e,i,o, or u).
                      4: Print out that word. Compile and test your
                      5: program, then type ready.
                      6: #once #create Ref
                      7: When in the course of human events, it becomes
                      8: necessary for one people to dissolve the political bands which have
                      9: connected them with another, and to assume among the 
                     10: powers of the earth the separate and equal station to which
                     11: the laws of Nature and of Nature's God entitle them, a decent
                     12: respect to the opinions of mankind requires that they should
                     13: declare the causes which impel them to the separation.
                     14:   We hold these truths to be self evident, that all men
                     15: are created equal, that they are endowed by their creator
                     16: with certain unalienable rights, that among these are life, liberty,
                     17: and the pursuit of happiness.  That to secure these rights,
                     18: governments are instituted among men, deriving their just
                     19: powers from the consent of the governed.  That whenever
                     20: any form of government becomes destructive of these ends,
                     21: it is the right of the people to alter or to abolish it, and
                     22: to institute new government, laying its foundation on such
                     23: principles and organizing its powers in such form, as to them
                     24: shall seem most likely to effect their safety and happiness.
                     25: #user
                     26: a.out <Ref >xxx
                     27: grep unalienable xxx >/dev/null
                     28: #succeed
                     29: /*     a way to find a word with lots of vowels */
                     30:  #include <stdio.h>
                     31: 
                     32: main()
                     33: {
                     34:        char bigword[100], thisword[100];
                     35:        int nvow, maxvow, c, k;
                     36: 
                     37:        maxvow = k = 0;
                     38:        while ((c = getchar()) != EOF) {
                     39:                if (c == '\n' || c == ' ') {
                     40:                        if (nvow > maxvow) {
                     41:                                copy(thisword, bigword, k);
                     42:                                maxvow = nvow;
                     43:                        }
                     44:                        nvow = k = 0;
                     45:                } else {
                     46:                        thisword[k++] = c;
                     47:                        switch (c) {
                     48:                        case 'a': case 'e': case 'i': case 'o': case 'u':
                     49:                                nvow++;
                     50:                        }
                     51:                }
                     52:        }
                     53:        printf("the word %s had %d vowels\n", bigword, maxvow);
                     54: }
                     55: 
                     56: copy(a, b, n)
                     57: char a[], b[];
                     58: {
                     59:        int i;
                     60: 
                     61:        for(i = 0; i < n; i++)
                     62:                b[i] = a[i];
                     63:        b[i] = 0;
                     64: }
                     65: #log
                     66: #next
                     67: 17.1a 10

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.