Annotation of 43BSDReno/usr.bin/learn/learnlib/C/L18.1a, revision 1.1

1.1     ! root        1: #print
        !             2: There is nothing to force you to write a main program
        !             3: on each file; just as I supplied "getnum" on a separate file,
        !             4: you can put different routines on different files.  Write
        !             5: a function "length(s)" which if given a character array argument
        !             6: "s" returns the length of that string.
        !             7: Put this on a file named "length.c", and leave
        !             8: the object file in "length.o".
        !             9: Write the main program for
        !            10: testing this somewhere else.  Type "ready" when you have compiled
        !            11: and tested your program and are happy with it.
        !            12: #once #create Ref
        !            13: This file contains several lines of quite different lengths.
        !            14: 
        !            15: You should get
        !            16: all of them exactly
        !            17: r
        !            18: right.
        !            19: #once #create answer
        !            20: 60
        !            21: 0
        !            22: 14
        !            23: 19
        !            24: 1
        !            25: 6
        !            26: #once #create tzaqc.c
        !            27: main() {
        !            28:        char s[200];
        !            29:        while (gets(s))
        !            30:                printf("%d\n", length(s));
        !            31: }
        !            32: #user
        !            33: cc tzaqc.c length.c 
        !            34: a.out <Ref >value
        !            35: #cmp value answer
        !            36: #succeed
        !            37: /*      one way */
        !            38: length(s)
        !            39: char *s;
        !            40: {
        !            41:        int k;
        !            42: 
        !            43:        for (k=0; s[k]; k++)
        !            44:                ;
        !            45:        return(k);
        !            46: }
        !            47: #log
        !            48: #next
        !            49: 19.1a 10

unix.superglobalmegacorp.com

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