Note: the easycurses inputChar()
function (in "no-delay mode", as you'll be using it) is
"non-blocking". That means that it doesn't wait for the user
to to press a key. Instead, it returns the appropriate key if
a key has just been pressed, and returns the
constant ERR otherwise.
So, for example, adding the line shown in red below to your
Part 1 code would print a message whenever the user pressed a key.
char ch = inputChar();
if( ch != ERR ) { // if there was no error
// use cerr instead of cout to print out the pressed key
cerr << "Read a '" << ch << "'!" << endl;
}
if( ch == 'y' )
break; // game exits with a 'y'
If you want to take advantage of this, however, you need
messages written to cerr to print somewhere else
other than the terminal window that's showing the ncurses output.
cerr. Just run it with your program like this:
./rundebug a.out
You should understand what is happening in that script, so here are the steps if you were to do this manually yourself:
err in the same directory as your project 3
work using the command:
~/$ echo > err
~/$ tail -f err
Go back to your original terminal and type something like
this:
~/$ echo "whoooooooo" > err
You should see the whoooooo pop up in the other terminal.
Spooky, eh?
~/$ ./a.out 2> err
... and watch as your ncurses window is pure and unblighted
by debugging messages, but the message does pop up at the
appropriate time in the second window.
Note: For those of you who've seen it, you can also use "valgrind" this way, which is
useful if you have a segfault, though it requires compiling
with the -g option to insert debugging
information. You would run your program like this:
~/$ ~/$ valgrind ./a.out 2> err
... and watch as the valgrind messages display in the second
terminal window.



