Hello there
i am working a project which need the gotoxy() function
i have read gotoxy() implementation for Linux using printf
i wonder why the
void gotoxy(int x,int y)
{
printf("%c[%d;%df",0x1B,y,x);
}
need to change the x y order in printf, is that just to fit the coordinate system?
in my way, i change it to printf("%c[%d;%df",0x1B,x,y) to meet my needs
stil, during my using this gotoxy() in for loop like this:
for( int i = 0; i < 12; i++ ) {
for( int j = 0; j < 12; j++ ) {
gotoxy( i , j );
usleep(500000);
}
}
when i = 0 and i = 0, the cursor are on the first row
i wonder why cursor does't go to second row when i = 1?
OP: "why the need to change the x y order".
The cursor position command's format is
Force Cursor Position <ESC>[{ROW};{COLUMN}f
The need arises because to match that format and have your y variable as the ROW, y comes first. (You could rotate your screen 90 degrees instead).
OP: why cursor does't go to second row when i = 1?
The home position, at the upper left of the screen is the Origin being line 1, column 1
Note: You can put the escape character in the format,
printf("\x1B[%d;%df", y, x);
fflush(stdout); // @jxh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With