Reputation: 1068
during this year in school my teacher showed us this function:
#include<Windows.h>
void gotoxy(int x,int y)
{
COORD punto;punto.X=x;punto.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),punto);
}
And looking in here some posts I read about this one based on ANSI escape codes
#include<stdio.h>
void gotoxy(int x, int y)
{
// <ESC>[(ROW);(COLUMN)f
printf("\x1B[%i;%if",y,x);
}
I kind of like the second one more, I feel I understand it better. But I wanted to ask here which of them is better because I know I'm probably missing something. What do you think?
Upvotes: 3
Views: 238
Reputation: 72226
If you write code for Windows then definitely use the first version. It always works on Windows but it does not work on other OSes (it does not even compile because other OSes do not provide these functions).
The second version is not tight to an OS. It works on any OS as long as the application runs in a terminal emulator that understands ANSI escape codes (most of them do).
Upvotes: 3