Category : A Collection of Games for DOS and Windows
Archive   : DAILYJOK.ZIP
Filename : DAILYJOK.C

Output of file : DAILYJOK.C contained in archive : DAILYJOK.ZIP
/* Tom's Second C Program: The Daily Joke. */

/* (c) 1988 T. Peters, Glendale, WI 53209. May not be sold, but */
/* feel free to give it away if you like. */

/* The daily joke program reads a line of text out of a file,
having chosen the line at random. It uses the C library function
rand, and the seed is based on the time of day. The bigger the
file, the longer it can take to come up with a line. Edit the file
all you want, just make sure the line count in the first line is
accurate. It must be 1 less than the number of lines in the file.
The jokefile is assumed to be in the current directory. */

/* Version 2.2: The jokefile is assumed to be either in the same
directory as the executable (and with the same name) or in the
current directory. The program will check to see if you are
running under version 3.0 (or above) of DOS and if so, it will
try to open a textfile with the same name as the program and the
filetype .TXT. This means that if you rename the executable you
must rename the textfile as well. If DOS 3 is not available, the
program can only check for DAILYJOK.TXT in the current directory. */

/* Easy C definitions */
#define AND &&
#define OR ||
#define NOT !
#define EQ ==
#define NE !=
#define LT <
#define LE <=
#define GT >
#define GE >=
#define MOD %
#define BITAND &
#define BITOR |
#define BITXOR ^
#define BITNOT ~
#define SHL <<
#define SHR >>

/* The datafile for this program is a textfile consisting of many
lines of text, each terminated by CR/LF, each less than 256 bytes
long. Whitespace between lines is ignored. The first line of the
text file must be line count for the file. Count the number of text
lines begun-- ignore blank lines. Also ignore line containing
the linecount. */

FILE *textfile;

/* Start mainline code */
int argc;
char *argv[];

int dosfn,dosdx,dosal,get_ver=0x30;
int dos_ver,dos_maj,dos_min;

struct dostime_t time; /*Structure in dos.h to receive time */
struct dosdate_t date; /*Structure in dos.h to receive date */
unsigned myseed=17;
register int n;
register int r;
int limit,readstat,inf_flag=0,test_flag=0,help_flag;
/*double max_in=32767.0;*/
/*double scale; */
int max_in=32767;
char line[256];
char filespec[256];

/* Debugging */
/* printf("%s\n",argv[0]); */

/* Get DOS version number */

dosdx = 0;
dosal = 0;
dos_ver = bdos(get_ver,dosdx,dosal);
dos_maj = dos_ver BITAND 0xFF;
dos_min = (dos_ver BITAND 0xFF00) SHR 8 ;

/* Get date */


/* Open input textfile */

if (dos_maj GE 3)

strcpy (filespec,argv[0]); /* Copy executable filename */
filespec[strlen(filespec)-3] = 'T' ;
filespec[strlen(filespec)-1] = 'T' ;
filespec[strlen(filespec)-2] = 'X' ;
textfile = fopen(filespec,"rb");

if ((dos_maj LT 3) OR (textfile EQ NULL))
textfile = fopen("DAILYJOK.TXT","rb");

if (textfile EQ NULL)
printf("\aCan't open DAILYJOK.TXT\n");
/* Read first line, it has a linecount. */
readstat=fscanf(textfile, "%d",&limit);

/* printf("Linecount: %d\n",limit); */
/* go thru all command line args, scan for t (test) or f (forever) */
for (n=1; n <= argc; n++)
if (NOT(strcmp(argv[n],"-T") ))
if (NOT(strcmp(argv[n],"-t") ))
if (NOT(strcmp(argv[n],"-F") ))
if (NOT(strcmp(argv[n],"-f") ))
if (NOT(strcmp(argv[n],"-h") ))
if (NOT(strcmp(argv[n],"-H") ))
if (NOT(strcmp(argv[n],"-?") ))

if (help_flag EQ 1)
"DailyJoke V2.2 (c) 1988 Tom Peters\n\n\
Usage: DAILYJOK [-t][-f][-?][-h]\n\
-t for test mode: highest number joke in file\n\
-f for forever mode, repeats until ^C\n\
-h or -? to display this message\n\n");

/* Get time of day */

_dos_gettime(&time); /* Use this as basis for random number seed*/

printf("\nIt's %d:%02d on %d-%d-%d, ",time.hour, time.minute,
printf("and this is your daily joke:\n");

myseed = time.hsecond*3600+time.minute*60+time.second;
srand(myseed); /* start the random number generator */

r=limit*(long)rand() / max_in;
if (test_flag EQ 1) r=limit+1;
printf("%d. ",r); /* report it */

for (n=1; n<=r; n++)
line[0]='\n'; /* initialize first byte of */
/* line buffer to newline */
/* Now, keep reading until the first byte is not a newline AND
there is no error or eof */

while (line[0] EQ '\n'AND
fgets(line,255,textfile ) NE NULL);
printf("%s",line );

} while (inf_flag EQ 1) ;

if (feof(textfile))
printf("\aEOF on DAILYJOK.TXT-- check the linecount in the first line.\n");
if (ferror(textfile))
printf("\aERROR reading DAILYJOK.TXT!\n");
} /* End of main() */

  3 Responses to “Category : A Collection of Games for DOS and Windows
Archive   : DAILYJOK.ZIP
Filename : DAILYJOK.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: