Annotation of 42BSD/usr.lib/learn/C/L5.1d, revision 1.1

1.1     ! root        1: #print
        !             2: Write a program that counts the blanks, tabs, and newlines
        !             3: in its input, and prints the total.  Don't forget to
        !             4: define the value of EOF at the beginning of your program.
        !             5: The best way is to add
        !             6: 
        !             7:  #include <stdio.h>
        !             8: 
        !             9: as the first line of your program.
        !            10: The ____must be in column 1.
        !            11: (See page 143 of the C book.)
        !            12: You may also have to say
        !            13: 
        !            14: cc name.c -lS
        !            15: 
        !            16: to compile the program.
        !            17: #once #create Ref
        !            18: This is some junk that
        !            19: contains
        !            20:        blanks
        !            21:        tabs
        !            22:        and newlines.
        !            23: #user
        !            24: a.out <Ref >test1
        !            25: a.out </dev/null >test2
        !            26: grep 13 test1 >/dev/null || grep 0 test2 >/dev/null
        !            27: #succeed
        !            28: One possible solution:
        !            29: 
        !            30:  #include <stdio.h>
        !            31: 
        !            32: main()
        !            33: {
        !            34:        int n, c;
        !            35: 
        !            36:        n = 0;
        !            37:        while ((c = getchar()) != EOF)
        !            38:                if (c == ' ' || c == '\t' || c == '\n')
        !            39:                        n++;
        !            40:        printf("%d\n", n);
        !            41: }
        !            42: 
        !            43: This program won't work on huge files, because an int
        !            44: isn't big enough.
        !            45: #log
        !            46: #next
        !            47: 5.1e 10
        !            48: 5.2e 5

unix.superglobalmegacorp.com

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