hello5.c 706 B

12345678910111213141516171819202122232425262728293031323334
  1. /* hello5.c
  2. * purpose bounce a message back and forth across the screen
  3. * compile cc hello5.c -lcurses -o hello5
  4. */
  5. #include <curses.h>
  6. #define LEFTEDGE 10
  7. #define RIGHTEDGE 30
  8. #define ROW 10
  9. main()
  10. {
  11. char message[] = "Hello";
  12. char blank[] = " ";
  13. int dir = +1;
  14. int pos = LEFTEDGE ;
  15. initscr();
  16. clear();
  17. while(1){
  18. move(ROW,pos);
  19. addstr( message ); /* draw string */
  20. move(LINES-1,COLS-1); /* park the cursor */
  21. refresh(); /* show string */
  22. usleep(100000);
  23. move(ROW,pos); /* erase string */
  24. addstr( blank );
  25. pos += dir; /* advance position */
  26. if ( pos >= RIGHTEDGE ) /* check for bounce */
  27. dir = -1;
  28. if ( pos <= LEFTEDGE )
  29. dir = +1;
  30. }
  31. }