Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your problem was intriguing enough I couldn't stop until I'd made it "work":</p> <pre><code>#include &lt;curses.h&gt; #include &lt;unistd.h&gt; // For sleep() #include &lt;string.h&gt; // For strlen() #include &lt;stdlib.h&gt; // For malloc() int main(int argc, char* argv[]) { char *text = "Hello, how are you? "; char *scroll; int text_length; int i, max_x, max_y; // Get text length text_length = strlen(text); // Initialize screen for ncurses initscr(); // Don't show cursor curs_set(0); // Get terminal dimensions // getmaxyx(stdscr, max_y, max_x); // Clear the screen clear(); getmaxyx(stdscr, max_y, max_x); scroll = malloc(2 * max_x + 1); for (i=0; i&lt; 2*max_x; i++) { scroll[i] = text[i % text_length]; } scroll[2*max_x - 1]='\0'; // Scroll text back across the screen for (i=0; i &lt; 10000; i++) { mvaddnstr(0,0,&amp;scroll[i%max_x], max_x); refresh(); usleep(20000); } // Wait for a keypress before quitting getch(); endwin(); return 0; } </code></pre> <p>Note that I've cheated :) (a) I duplicate the string to more than large enough to always fill the screen (twice the width) (b) I don't scroll the print location, I scroll the <em>text</em> that I ask to print (c) I just put a space in the original input string because it was easier than putting in a space through another mechanism.</p> <p>Oh yeah, I removed the <code>clear()</code> call, it made the screen too messy to really see. We're over-writing the same <code>max_x</code> cells over and over though, no need to keep clearing the entire screen.</p> <p>I hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload