home *** CD-ROM | disk | FTP | other *** search
- /*
- Yet another fortune cookie type program. I wrote this because
- I wanted one that didn't need a pointer file, didn't require
- ANSI.SYS loaded, didn't write files to disk and didn't crash
- '386 machines, and I couldn't find one. The data file should
- be a standard text file with each fortune starting with a #
- character. The fortunes have been collected from a variety of
- sources.
-
- Peter Summers - 24/3/91
- */
-
-
- #include <conio.h>
- #include <io.h>
- #include <string.h>
- #include <stdlib.h>
- #include <values.h>
- #include <time.h>
- #include <fcntl.h>
- #include <sys\stat.h>
-
- main (int argc, char *argv[])
- {
- int handle,numread;
- long offset;
- char *extension,*datafile,*buffer,*outstring;
-
- datafile=calloc(128,sizeof(char));
-
- if (argc>1)
- strcpy(datafile,argv[1]);
- else
- {
- strcpy(datafile,argv[0]);
- extension=strrchr(datafile,'.');
- if (extension==NULL)
- {
- cprintf("%s","No '.' found in argc[0] in WISDOM");
- exit(1);
- }
- else
- strcpy(extension,".DAT");
- }
-
- buffer=calloc(4097,sizeof(char));
-
- handle=open(datafile,O_RDONLY|O_BINARY,S_IREAD);
-
- if (handle==-1)
- {
- cprintf("Can't open data file %s in WISDOM",datafile);
- exit(1);
- }
-
- randomize();
- offset=((long)random(MAXINT)*MAXINT+random(MAXINT))%filelength(handle);
-
- lseek(handle,offset,SEEK_SET);
- numread=read(handle,buffer,4096);
-
- if (numread==-1)
- {
- cprintf("Can't read from data file %s in WISDOM",datafile);
- exit(1);
- }
-
- if (numread<4096)
- {
- lseek(handle,0,SEEK_SET);
- read(handle,&buffer[numread],4096-numread);
- }
-
- outstring=strchr(buffer,'#')+1;
-
- *strchr(outstring,'#')=0;
-
- textcolor(3);
- cprintf("%s",outstring);
- }