RE: Tips
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 <job@abc.se> [2:201/262.37]
--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-REQUEST@lists.debian.org . Trouble? e-mail to Bruce@Pixar.com
Reply to:
- References:
- RE: Tips
- From: Casper BodenCummins <bodec@Sherwood.co.uk>