Ncurses - problem with mvwprintw at terminal end

Hello, here's my program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <ncurses.h>
#include <cstring>
#include <chrono>
#include <thread>

using namespace std;

int main()
{
    char mesg[]="@";
    int row,col;				/* to store the number of rows and *
                                                 * the number of colums of the screen */
    int dir = 1;
    initscr();				/* start the curses mode */
    getmaxyx(stdscr,row,col);		/* get the number of rows and columns */
    int maxx = col - 3;
    col = col - 4;
    while(true)
    {
        werase(stdscr);
        if (col == maxx - 1) dir = -1;
        if (col == maxx - 4) dir = 1;
        col += dir;
        mvwprintw(stdscr, row - 1, col, mesg);
        refresh();
        std::this_thread::sleep_for(std::chrono::milliseconds(500));
    }

    /* print the message at the center of the screen */

    getch();
    endwin();

    return 0;
}


It is basically copied tutorial from ncurses with my things added, so sorry for comments.

The program moves around "@" sign - left and right. It works okay when it's like this - maxx = realmaxx - 3. This way, it's printed before line end and works nicely. You can try it out. Command to compile would be:

g++ -std=c++11 -o main main.cpp -lncurses

However, if you change maxx at line 17 to maxx = col, then there's a problem. idk why, but it stops for a moment at edges. I have no idea what's causing it. Any ideas?
I would check your return codes from all of the ncurses functions for starters. Expecially mvwprintw().
Topic archived. No new replies allowed.