I\'m trying to retrieve the coordinates of cursor in a VT100 terminal using the following code:
void getCursor(int* x, int* y) {
printf(\"\\033[6n\");
s
#include
#include
#include
void readCoord(void* row, void* col){
int i = 0;
char* input = malloc(10);
printf("\e[6n");
while(!_kbhit()) _sleep(1);
while(_kbhit()) *(input + (i++)) = getch();
*(input + i) = '\0';
sscanf(input, "\e[%d;%dR", row, col);
}
void main(void){
int i = 0, r, c;
char* coord = malloc(10);
printf("Hello");
readCoord(&r , &c);
printf("\nYour coordinate is (%d, %d)", c, r);
}
_kbhit()
is used to detect input (DSR are treated as though typed at the keyboard), and
getch()
to read and remove the character from standard input
This program relies on conio.h
, which is not a standard and hence not recommended for portable C programs.