---

/* * FILE: q_gen.c (quote generator) * * WHAT: The program was first written specifically to extract quotes * from the Simpsons `Master' quote file. However, this does not * have to be.. * * This program should compile under practically any machine that * has a decent C compiler. * * USAGE: q_gen * * HISTORY: 5/10/92 Original Creation * Tom Warren taw@cc.bellcore.com * 1/3/93 Add conditional compilation to support C++ compiler * * Problems should be report to taw@cc.bellcore.com * * Enjoy. -Tom */ #include #include #include #include #ifdef __cplusplus main(int argc, char *argv[]) #else main(argc, argv) int argc; char *argv[]; #endif { long time_buf; FILE *fp; int max, thisone, quote; char buf[BUFSIZ]; if (argc == 1) { printf("USAGE: %s \n", argv[0]); exit(1); } /* GET THE FILE */ if ((fp= fopen(argv[1], "r")) == NULL) { printf("%s: Error opening \"%s\". Program aborted.\n", argv[0],argv[1]); exit(1); } /* GET THE NUMBER OF QUOTES IN THE FILE */ max=0; fseek(fp, 0L, 2); /* go to eof */ while (!fseek(fp, -2L, 1)) /* backup */ { if (getc(fp) == '\n') /* got last line */ { fscanf(fp, "%d", &max); /* get the number */ break; } } if (max == 0) { printf("%s: Error - no quote in \"%s\". Program aborted.\n", argv[0],argv[1]); exit(1); } /* GET A RANDOM NUMBER */ time_buf = time(0); /* use as the SEED */ srand((unsigned) time_buf); /* reset */ thisone = rand() % max; /* get a random number */ thisone++; /* quote starts from 1 to max */ /* GET THE QUOTE */ fseek(fp, 0L, 0); /* go to the beginning */ while (fgets(buf, sizeof buf, fp) != NULL) { sscanf(buf, "%d", "e); /* what quote are we at? */ if (quote == thisone) { fputs( (strchr(buf,'%') +1), stdout); /* display the quote */ } } }

---

The views and opinions stated within this web page are those of the author or authors which wrote them and may not reflect the views and opinions of the ISP or account user which hosts the web page. The opinions may or may not be those of the Chairman of The Skeptic Tank.

Return to The Skeptic Tank's main Index page.

E-Mail Fredric L. Rice / The Skeptic Tank