hi does anybody know the code to move text characters in the console window?
or maybe a link? i couldnt find any but i think it might have some thing to
do with x and y.
Windows console (as in windows ONLY, I don't recall the unix alternative but I'm sure there is one) also has an option like that. (And of course it has to do with x and y, how else would you define the coords?)
I recall reading this from somewhere else in the forums so I take no credit for the code that follows. I believe it is Duoas's...
But yes curses is the *real* way to do it. Curses is meant for console manipulation so it is more suited, but this is from windows console libraries and it's rather useful unto itself:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <windows.h>
// Give this a row and column in integers and it will move the cursor.
void curPos(int x, int y)
{
HANDLE hStdout;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hStdout, &csbiInfo);
csbiInfo.dwCursorPosition.X=x;
csbiInfo.dwCursorPosition.Y=y;
SetConsoleCursorPosition(hStdout, csbiInfo.dwCursorPosition);
}
i found a way to do it. bit i want to make it more simple and efficient because i want to make it much bigger. here is the code maybe you will have a better idea. it runs on an infinite loop until the user types exit. i converted the string to an integer then used a switch/case followed by a system("CLS").
i had to use two posts to fit it all. you might have to compile and run it to understand how it works.
This is not shorter if to count in lines, but is shorter in symbols and much more shorter in used operators, and it is clearer and more universal. What if you need 256 variables instead of 16?