DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
ETI program examples

The scatter program

This program takes the first LINES - 1 lines of characters from the standard input and displays the characters on a terminal screen in a random order. For this program to work properly, the input file should not contain tabs or non-printing characters.

/*
 *	The scatter program.
 */

#include <ocurses.h> #include <sys/types.h>

extern time_t time();

#define MAXLINES 120 #define MAXCOLS 160 char s[MAXLINES][MAXCOLS]; /* Screen Array */ int T[MAXLINES][MAXCOLS]; /* Tag Array - Keeps track of * * the number of characters * * printed and their positions. */

main() { register int row = 0,col = 0; register int c; int char_count = 0; time_t t; void exit(), srand();

initscr(); for(row = 0;row < MAXLINES;row++) for(col = 0;col < MAXCOLS;col++) s[row][col]=' ';

col = row = 0; /* Read screen in */ while ((c=getchar()) != EOF && row < LINES ) {

if(c != '\n') { /* Place char in screen array */ s[row][col++] = c; if(c != ' ') char_count++; } else { col = 0; row++; } }

time(&t); /* Seed the random number generator */ srand((unsigned)t);

while (char_count) { row = rand() % LINES; col = (rand() >> 2) % COLS; if (T[row][col] != 1 && s[row][col] != ' ') { move(row, col); addch(s[row][col]); T[row][col] = 1; char_count--; refresh(); } } endwin(); exit(0); }


Next topic: The show program
Previous topic: The highlight program

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004