/* Program: WORDS Author : Kim Moser Date : 30 November, 1990 System : IBM PC / Borland Turbo C 2.0 Descrip: Parses words from stdin to stdout Usage : WORDS */ #include #include #include static char *words[16000]; static int wordindex=0; static int hasword(char *s); static int hasword(char *s) { int i; if (wordindex == 0) return 0; for (i=wordindex; (i>wordindex-500) && i>=0; i--) { if (!strcmp(words[i], s)) return (1); } return (0); } void usage(void) { fprintf(stderr, "usage: WORDS \n"); exit(-1); } void main(int argc, char **argv) { char s[512]; int i; int len; if (argc < 2) usage(); if ((len = atoi(argv[1])) == 0) usage(); while (1) { if (gets(s) == NULL) break; if (!s[0]) continue; if (strlen(s) != len) continue; if (hasword(s)) { fputc('x', stderr); } else { fputc('.', stderr); if ((words[wordindex++] = strdup(s)) == NULL) { fprintf(stderr, "strdup() failed.\n"); exit(-1); } } } fprintf(stderr, "\n"); for (i=0; i