0

conio.h and gotoxy does not work with my compiler for C. I tried searching for solutions on the web and found the following:

void gotoxy(int x, int y)
{
    printf("\033[%d;%dH", y, x);
}

However, it does not position the cursor as intended. It only displays

←[1;10H

when I try to set x and y to 10 and 1 respectively. I have found other alternatives like using SetConsolePosition but I would still like to know if using ANSI escape sequences would work.

I am currently using the CodeBlocks IDE.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • 3
    I'd imagine that would be dependant on the terminal? – Neil Mar 07 '22 at 04:18
  • 3
    Whether or not your terminal supports ANSI escapes is totally a function of what terminal you are using. Some do, some don't. `\033[;H` can also be written as `\033[;f` (with `'f'` instead of `'H'`). You may want to try if that is implemented. Otherwise try a few other escapes. If none work, then your terminal likely doesn't support ANSI escapes. (VT 100 terminal emulation should support the ANSI escapes) `tput` is another way to manipulate the terminal. Or, as you have found, `SetConsolePosition` is what works with that terminal. – David C. Rankin Mar 07 '22 at 04:28
  • why not use curses? or ncurses – pm100 Mar 07 '22 at 05:20
  • @pm100 how would I use curses or ncurses ? – Chadwick Macavoy Mar 07 '22 at 05:58
  • https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/intro.html if windows see this https://stackoverflow.com/questions/138153/is-ncurses-available-for-windows – pm100 Mar 07 '22 at 05:59
  • Using `SetConsoleCursorPosition` in Windows is a perfectly fine solution. – Lundin Mar 07 '22 at 07:41
  • The Windows Terminal needs a to be initialized with SetConsoleMode to use these sequences – Dúthomhas Mar 07 '22 at 07:54

0 Answers0