home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Educate / Educate.zip / PMQUOTE.ZIP / QUOTER.C < prev    next >
C/C++ Source or Header  |  1990-08-17  |  2KB  |  97 lines

  1. /************************************************************************/
  2. /*                                                                                                                                            */
  3. /*                            Q U O T E R . C - Quote-of-the-Day Program                            */
  4. /*                                                                                                                                            */
  5. /************************************************************************/
  6.  
  7. /************************************************************************
  8.  *                     
  9.  *  Author:  T_Koschate
  10.  *  Date:         August, 1990
  11.  *
  12.  ************************************************************************/
  13.  
  14. #include <os2.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <time.h>
  19.  
  20. char quotestr[25 * 81];
  21.  
  22. void main(int argc, char *argv[])
  23. {
  24.     FILE *fp;
  25.     long quotenum, quotectr;
  26.     char qline[81];
  27.     time_t currtime;
  28.     int startpoint;
  29.     HAB hab;
  30.     HMQ        hmq;
  31.     int exit_code;
  32.  
  33.     if (NULL == (fp = fopen("quotes.bbs","r")))
  34.         {
  35.         strcpy(quotestr,"Unable to open QUOTES.BBS");
  36.         exit_code = 1;
  37.         }
  38.     else
  39.         {
  40.         if (argc == 2)
  41.             quotenum = atol(argv[1]);
  42.         else
  43.             {
  44.             time(&currtime);
  45.             srand((unsigned int)currtime % RAND_MAX);
  46.             quotenum = (long)rand();
  47.             }
  48.  
  49.         quotectr = 1L;
  50.         while (quotectr < quotenum)
  51.             {
  52.             while (TRUE)
  53.                 {
  54.                 if (NULL == fgets(qline,sizeof(qline),fp))                /* Ran out of quotes */
  55.                     {
  56.                     rewind(fp);
  57.                     quotenum = quotenum % quotectr;
  58.                     quotectr = 1;
  59.                     continue;
  60.                     }
  61.                 if (!strcmp(qline,"\n"))
  62.                     {
  63.                     quotectr++;
  64.                     break;
  65.                     }
  66.                 }
  67.             }
  68.  
  69.         startpoint = 0;
  70.         while (TRUE)
  71.             {
  72.             if (NULL == fgets(qline,sizeof(qline),fp))                /* Ran out of quotes */
  73.                 break;
  74.             if (strcmp(qline,"\n"))
  75.                 {
  76.                 strcpy("estr[startpoint],qline);
  77.                 startpoint += strlen(qline);
  78.                 }
  79.             else
  80.                 break;
  81.             }
  82.         fclose(fp);
  83.         exit_code = 0;
  84.         }    
  85.  
  86.   hab = WinInitialize (0);
  87.   hmq = WinCreateMsgQueue (hab, 0);
  88.  
  89.     WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,quotestr,
  90.         "Quote of the Day",0,MB_OK|MB_NOICON);
  91.  
  92.     WinDestroyMsgQueue (hmq);
  93.     WinTerminate (hab);
  94.  
  95.     exit(exit_code);
  96. }
  97.