On Wed, 22 Jan 1997, Casper BodenCummins wrote: > I've been meaning to look at fortune to see whether it can easily handle > or be adapted to handle different databases of fortune cookies - such as > tips. I'm running low on free time just now, so does anyone have the
Don't know about fortune... it is a simple program to write though... The below one prints a random cookie from a text file, in which the cookies are separated by a blank space. I use it to print a random Linux Cookie upon login and when someone views my Linux WWW Page at http://es.matematik.su.se/~p96job/linux.html. Takes its input from standard in, like in cook < cookiefile.txt. Does only 1 pass though file, so it need not be seekable. Feel free to find bugs... I have limited C skills... -- cook.c --[ cut ]--[ cut ]--[ cut ]--[ cut ]-- #include <stdio.h> #include <stdlib.h> #define LF 10 void main() { char c; unsigned char skriv = 1; unsigned int nr = 1; unsigned int i = 0; char s[1024]; srandom(time(0) + getpid()); while ( (c=getc(stdin)) != EOF ) { if (skriv) s[i++] = c; if (c == LF) { c = getc(stdin); while ( (c == 32) || (c == 9) ) c = getc(stdin); if (c == LF) { if (random() % ++nr) skriv = 0; else { skriv = 1; i = 0; } } else if (skriv) s[i++] = c; } } s[i] = 0; printf("%s", s); } -- cook.c --[ cut ]--[ cut ]--[ cut ]--[ cut ]-- // Jonas <[EMAIL PROTECTED]> [2:201/262.37] -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED]