How do I scroll a message across the terminal?

后端 未结 1 1484
庸人自扰
庸人自扰 2021-01-22 03:28

I\'m trying to write a program to that acts as a marquee that uses the curses.h library to create a side-scrolling display.

What should happen is that my me

相关标签:
1条回答
  • 2021-01-22 03:42

    The first problem is that you call getmaxyx() before initscr(). In this situation, stdscr has not been initialized, so the values returned by getmaxyx() are meaningless. (I get -1 for each value, aka ERR.)

    That fixed, the program basically works, but prints junk after the "Hello" string. You can solve that by changing the for loop test, text_length || i<max_x, to text_length && i<max_x, although the result is still probably not quite what you want. But I'll leave it to you to figure that one out.

    Finally, as a stylistic matter, I'd suggest using curses' own napms() function instead of usleep() (i.e., napms(50) instead of usleep(50000)). But if you do stick with usleep(), you should add #include <unistd.h> at the top.

    0 讨论(0)
提交回复
热议问题