I was looking for a substitute of gotoxy
for Dev C++ v5.11 (gcc compiler) and found this:
void gotoxy(int x,int y) {
printf("%c[%d;%df", 0x1b, y, x);
}
After this when I tried to call this function as follows:
int main() {
gotoxy(20, 10);
printf("Hello");
return 0;
}
Output was not as expected:
<-[10;20fHello
This was printed in top left most corner of screen (i.e. 1,1) instead of (20,10).
Please give me suggestions that what I can do to use gotoxy
in my code.
Your ANSI escape sequence is incorrect, it should be \033[%d;%dH
, but it seems your terminal does not support ANSI VT100 escape sequences at all. In Windows, there might be a configuration setting to enable it, VT100 emulation is standard in most modern operating systems terminals (unix, linux, BSD, OS/X...).
Here is the modified code:
#include <stdio.h>
void gotoxy(int x, int y) {
printf("\033[%d;%dH", y, x);
}
int main(void) {
gotoxy(20, 10);
printf("Hello\n");
return 0;
}