Annotation of coherent/d/usr/src/examples/malloc.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #define NITEMS 512
        !             3: #define MAXLEN 256
        !             4: 
        !             5: char *data[NITEMS];
        !             6: char string[MAXLEN];
        !             7: 
        !             8: main()
        !             9: {
        !            10:        register char **cpp;
        !            11:        register int count;
        !            12:        extern int compare();
        !            13:        extern char *malloc();
        !            14:        extern char *gets();
        !            15: 
        !            16:        for (cpp = &data[0]; cpp < &data[NITEMS]; cpp++) {
        !            17:                if (gets(string) == NULL)
        !            18:                        break;
        !            19:                if ((*cpp = malloc(strlen(string) + 1)) == NULL)
        !            20:                        exit(1);
        !            21:                strcpy(*cpp, string);
        !            22:        }
        !            23: 
        !            24:        count = cpp - &data[0];
        !            25:        qsort(data, count, sizeof(char *), compare);
        !            26: 
        !            27:        for (cpp = &data[0]; cpp < &data[count]; cpp++) {
        !            28:                printf("%s\n", *cpp);
        !            29:                free(*cpp);
        !            30:        }
        !            31:        exit(0);
        !            32: }
        !            33: 
        !            34: compare(p1, p2)
        !            35: register char **p1, **p2;
        !            36: {
        !            37:        extern int strcmp();
        !            38:        return(strcmp(*p1, *p2));
        !            39: }

unix.superglobalmegacorp.com

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