lundi 30 mars 2015

ncurses mvaddch() cursor movement not as expected



Code:



#include <ncurses.h>

int main(int argc, char **argv)
{
initscr();
noecho();
cbreak();


mvprintw(0, 0, curses_version());
mvprintw(1, 0, "Hello World");
mvaddch(2, 0, mvinch(1, 4)); // Why doesn't this work?

getch();
endwin();

return 0;


}


Output:



ncurses 5.9.20130608
Hello World


with pointer blinking (waiting for getch ) just after o of Hello.


Question:

As in C, arguments passed to a function are evaluated first before calling that function, mvinch() will be called first and when it'll return the character o the call to mvaddch() will be made.

But then why character o is not printed on line 2 (just below Hello World)? Instead mvaddch prints o at current cursor position (thanks to winch which is 1,4). Here mvaddch() behaves just like addch paying no respect to the mv prefix and the explicit movement coordinates given to it. Why?


Is this a possible bug in mvaddch() or am I missing something?




Aucun commentaire:

Enregistrer un commentaire