1 04/15/88  "SCATTER" EXAMPLE
 2 
 3 /*
 4  *        SCATTER.  This program takes the first
 5  *        20 lines from the standard
 6  *        input and displays them on the
 7  *        VDU screen, in a random manner.
 8 */
 9 
10 #include <curses.h>
11 
12 #define MAXLINES 120
13 #define MAXCOLS 160
14 char s[MAXLINES] [MAXCOLS];   /* Screen Array */
15 
16 
17 long time();
18 
19 main()
20 {
21           int row=0,col=0;
22           char c;
23           int char_count=0;
24           char buf[BUFSIZ];
25           int i=0,j=0;
26 
27           for (row=0; row<MAXLINES; row++)
28                     for (col=0; col<MAXCOLS; col++)
29                               s[row][col]= 0;
30 
31 
32           row = 0;
33 
34           /* Read screen in */
35 
36           printf ("Begin entering a screen, ending with EOF or by
37                   entering 20 lines\n");
38           while ( fgets(&s[row][0],MAXCOLS,stdin) != NULL && row < 20)
39           {
40                 for (i=0;i<MAXCOLS;i++) {
41                     if (s[row][i] == 0) break;
42                     if (s[row][i] != ' ') char_count++;
43                     }
44                 row++;
45           }
46 
47 
48           srand (time(NULL));
49 
50           for (i=0;char_count>0;i++) {
51               for (j=0;j<MAXCOLS;j++) {
52                   if (s[i][j] != ' ' &&
53                       s[i][j] != 0)
54                      {
55                      row=rand() % LINES;
56                      col=(rand()>>2) % COLS;
57 
58                       move(row,col);
59                       addch (s[i][j]);
60                       char_count--;
61 
62 
63                       refresh();
64                       }
65                         }
66           }
67 
68           echo();
69           endwin();
70           exit(0);
71 }
72