Annotation of coherent/d/usr/src/examples/stringfun.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: 
                      3: #define NNAMES 512
                      4: #define MAXLEN 60
                      5: 
                      6: char *array[NNAMES];
                      7: char first[MAXLEN], mid[MAXLEN], last[MAXLEN];
                      8: char *space = " ";
                      9: 
                     10: int compare();
                     11: extern char *strcat();
                     12: 
                     13: main()
                     14: {
                     15:        register int index, count, inflag;
                     16:        register char *name;
                     17: 
                     18:        count = 0;
                     19:        while (scanf("%s %s %s\n", first, mid, last) == 3) {
                     20:                strcat(first, space);
                     21:                strcat(mid, space);
                     22:                name = strcat(first, (strcat(mid, last)));
                     23:                inflag = 0;
                     24: 
                     25:                for (index=0; index < count; index++) 
                     26:                        if (strcmp(array[index], name) == 0) 
                     27:                                inflag = 1;
                     28: 
                     29:                if (!inflag) {
                     30:                        if ((array[count] = 
                     31:                                malloc(strlen(name) + 1)) == NULL) {
                     32:                                fprintf(stderr, 
                     33:                                "insufficient memory is available\n");
                     34:                                exit(1);
                     35:                        }
                     36:                        strcpy(array[count], name);
                     37:                        count++;
                     38:                }
                     39:        }
                     40: 
                     41:        shellsort(array, count, sizeof(char *), compare);
                     42:        for (index=0; index < count; index++)
                     43:                printf("%s\n", array[index]);
                     44:        exit(0);
                     45: }
                     46: 
                     47: compare(s1, s2)
                     48: register char **s1, **s2;
                     49: {
                     50:        extern int strcmp();
                     51:        return(strcmp(*s1, *s2));
                     52: }
                     53: 

unix.superglobalmegacorp.com

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