Printing in windows console on x,y position

2.4k views Asked by At

I want to print, in a certain (X,Y) position, on a standard console in windows.
I tried to use conio.h, but is deprecated/non-existing. There was the gotoxy(x,y) method that seems to be what I want. I've tried these ways, but it just prints extra characters:

    printf("%c[%d;%df",0x1B,y,x);
    printf("\x1B%c[%d;%df",0x1B,y,x);
    printf("\x1B[%d;%dH", 0x1B, y, x);  

Thanks in advance.

1

There are 1 answers

0
Thanatos On BEST ANSWER

The Windows API call to position the cursor in a console is SetConsoleCursorPosition.

As someone commented, "curses" is a cross platform console library for doing stuff like this: implementations exist for Windows. ("PDcurses" I think is one such implementation.) These will let you do things like, color, cursor position, etc., and have your program port to other OS, such as Linux.

The printf statements you list are escape sequences for several types of terminals out there. Unfortunately, Windows does not use escape sequences for terminal positioning stuff.