#include <stdlib.h> #include <stdio.h> #include <conio.h> 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() used to detect input (DSR is processed as if it is getch() on the keyboard), and getch() to read and remove a character from standard input.
This program uses conio.h , which is not a standard and therefore not recommended for portable C programs.
Jun jie
source share