title: How do I scroll a message across the terminal?
body: <p>I'm trying to write a program to that acts as a marquee that uses the <code>curses.h library</code> to create a side-scrolling display.</p>
  
  <p>What should happen is that my message "Hello" should appear to scroll from the right side of the terminal to the left, character by character.</p>
  
  <p>"hello" should appear to scroll across the terminal like so: </p>
  
  <pre><code>|                                              H| // fist frame of animation
  
  |                                             He| //2nd
  
  |                                            Hel| //3rd
                                                    ...
  |             Hello                             | // some time in the middle of animation
  
  |Hello                                          | // finished.
  </code></pre>
  
  <p>Instead of appearing to scroll across the terminal my program simply outputs the "Hello" message on the left side of the terminal as if it is finished.</p>
  
  <p>I thought that printing the appropriate number of spaces then the appropriate number of characters of the string each frame would work.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Below is my code so far:</p>
  
  <pre><code>#include    &lt;curses.h&gt;
  #include    &lt;string.h&gt; 
  main()
  {
      char    message[] = "Hello";
      int     max_y, max_x; // max dimensions of terminal window
      int     text_length;
      int     i,row=0,col=0,spaces=0;
  
      // Get text length
      text_length = strlen(message);
  
      // Get terminal dimensions
      getmaxyx(stdscr, max_y, max_x);
  
      // num of spaces needed to print
      spaces = max_x -1; 
  
      initscr(); // initialize curses
      clear(); // clear screen to begin
  
      while(1)
      {
          clear(); // clear last drawn iteration
          move(5,col);
          // print spaces as necessary
          for(i=0;i&lt;spaces;i++)
          {
              addch(' ');
          }
          refresh();
          // print appropriate number of characters of the message            
          for(i=0;i&lt;text_length || i&lt;max_x; i++)
          {
              addch(message[i]);
          }
          refresh();          
          usleep(50000); // wait some time
          spaces = spaces-1; //adjust spaces need for next iteration
      }
  }
  </code></pre>