/* hello5.c * purpose bounce a message back and forth across the screen * compile cc hello5.c -lcurses -o hello5 */ #include #define LEFTEDGE 10 #define RIGHTEDGE 20 #define ROW 10 main() { char message[] = "Hello", msg[50]; char blank[] = " "; int dir = +1; int pos = LEFTEDGE ; initscr(); clear(); sprintf(msg,"Lines=%d,COLS=%d\n",LINES,COLS); while(1){ move(1,1); addstr(msg); move(pos,pos); addstr( message ); /* draw string */ move(LINES-1,COLS-1); /* park the cursor */ refresh(); /* show string */ sleep(1); move(pos,pos); /* erase string */ addstr( blank ); pos += dir; /* advance position */ if ( pos >= RIGHTEDGE ) /* check for bounce */ dir = -1; if ( pos <= LEFTEDGE ) dir = +1; } }