You're going to want something more like this:
int main()
{
initscr();
//The NCurses tutorial was pretty clear on this one,
//it's in the "Initialization" section, read up on it.
keypad(stdscr, TRUE);
cbreak();
noecho();
int chx = 0;
int chy = 0;
//Using a boolean for the loop makes it easier to stop later. Just
//change shouldQuit to true, and the loop condition will fail next time.
bool shouldQuit = false;
while(shouldQuit == false)
{
printw("............");
printw("............");
printw("............");
printw("............");
printw("............");
//You can combine move() and addch() like this. Also,
//if you read the documentation, the y (row) value has
//to come first, both in this and the move function. There
//was a warning about this in the section "A word of caution"
//in the Output "chapter".
mvaddch(chy,chx, 78);
refresh();
//getch() waits for input then *returns* it as an integer, you
//have to store it somehow if you want to reference it later.
int input = getch();
switch(input)
{
case KEY_UP:
//You don't want to let it move up if it's already
//at the top, weird things can happen.
if(chy>0) {chy--;}
break;
case KEY_DOWN:
if(chy<24) {chy++;}
break;
case KEY_LEFT:
if(chx>0) {chx--;}
break;
case KEY_RIGHT:
if(chx<79) {chx++;}
break;
case 'q': //If this looks weird, the two case conditions,
case 'Q': //you may want to read up on switch statements.
shouldQuit = true;
break;
}
}
return 0;
}
You may want to review the NCurses tutorial again, it covered both the keypad() and move(
y,
x) mistake fairly well.
[EDIT]: Also, I just wrote this up in the forum window, so I haven't actually tested it. There's a decent chance I've made some incredibly stupid mistake, since my IDE wasn't there to catch me
Should you choose to copy-paste it you may have to correct a spelling or syntax mistake or two. That being said, I'd highly suggest you copy it by hand, you'll probably learn more doing it yourself than by just using someone else's code.
Also, in reference to the
goto thing,
goto is bad, it does what it's supposed to, but you end up with a horrible mess of spaghetti code if you use it too often, or somewhere the label is hard to find from. Google "C++ Functions", there's God-only-knows how many solid tutorials covering the basics of functions. You may also want to read up on "Object-Oriented" programming. Admittedly, I didn't for far too long, and it's making it hard for me to work with my old code now, wanting to change it all