home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_03 / 3n03063b < prev    next >
Text File  |  1992-01-15  |  3KB  |  71 lines

  1. /* SPINNER.C              */
  2. /* S. Van Dyke, AFAB Ent. */
  3. /* 7918 N. Central        */
  4. /* K.C., Mo. 64118        */
  5.  
  6. /* Spinning cursor for long, quiet applications */
  7.  
  8. #include <stdio.h>
  9. #include <conio.h>                            /* if following example 2 */
  10.  
  11. #define BACKSPACE 8                              /* BackSpace character */
  12.  
  13. void main(void)
  14. {
  15.    char spinner[] = {"\\|/-"};                       /* '\\' yields '\' */
  16.    int spinpos;
  17.    int i, nrecs;
  18.  
  19.    clrscr();
  20.    printf("Spinning cursor demo program\n");
  21.  
  22.                    /* Example 1                                         */
  23.                    /* For applications that do not print to the screen  */
  24.  
  25.    spinpos = 0;                                        /* reset spinner */
  26.    printf("Working %c%c", spinner[spinpos++], BACKSPACE);
  27.    spinpos &= 0x03;                        /* limit to valid characters */
  28.  
  29.    for (i=0; i < 100; ++i)
  30.    {                                            /* Long processing loop */
  31.  
  32.                                                       /* Update spinner */
  33.       printf("%c%c", spinner[spinpos++], BACKSPACE);
  34.       spinpos &= 0x03;                     /* limit to valid characters */
  35.  
  36.                                 /* Whatever operation the loop performs */
  37.          delay(100);                      /* approx 1/10th second delay */
  38.    }                                     /* end of main processing loop */
  39.  
  40.  
  41.                /* Example 2                                             */
  42.                /* For applications that may output to the screen and/or */
  43.                /*     where the total number of iterations is known     */
  44.                /* Note: gotoxy() and cprintf() are Turbo C specific     */
  45.  
  46.    nrecs = 100;               /* determine number iterations to perform */
  47.  
  48.    spinpos = 0;                                        /* reset spinner */
  49.    gotoxy(1, 3);                            /* spinner message position */
  50.    cprintf("Processing: %c %-5d ", spinner[spinpos++], nrecs);
  51.    spinpos &= 0x03;                        /* limit to valid characters */
  52.  
  53.    for (i=nrecs; i > 0; --i)
  54.    {                                            /* Long processing loop */
  55.  
  56.                                                       /* Update spinner */
  57.       gotoxy(13, 3);                         /* set to spinner position */
  58.       cprintf("%c %-5d ", spinner[spinpos++], nrecs--);
  59.       spinpos &= 0x03;                     /* limit to valid characters */
  60.  
  61.                                 /* Whatever operation the loop performs */
  62.          delay(100);                      /* approx 1/10th second delay */
  63.    }                                     /* end of main processing loop */
  64.  
  65.    gotoxy(11, 3);
  66.    cprintf(" complete.");                         /* overwrites spinner */
  67.  
  68. }
  69.  
  70. /* End of file */
  71.