Created
March 31, 2013 23:15
-
-
Save wemakeweb/5282405 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <string.h> | |
| void clrscr(){ | |
| printf("\033[2J"); | |
| } | |
| void gotoxy(int x, int y) { | |
| char essq[100]; /* String variable to hold the escape sequence */ | |
| char xstr[100]; /* Strings to hold the x and y coordinates */ | |
| char ystr[100]; /* Escape sequences must be built with characters */ | |
| /* | |
| ** Convert the screen coordinates to strings | |
| */ | |
| sprintf(xstr, "%d", x); | |
| sprintf(ystr, "%d", y); | |
| /* | |
| ** Build the escape sequence (vertical move) | |
| */ | |
| essq[0] = '\0'; | |
| strcat(essq, "\033["); | |
| strcat(essq, ystr); | |
| /* | |
| ** Described in man terminfo as vpa=\E[%p1%dd | |
| ** Vertical position absolute | |
| */ | |
| strcat(essq, "d"); | |
| /* | |
| ** Horizontal move | |
| ** Horizontal position absolute | |
| */ | |
| strcat(essq, "\033["); | |
| strcat(essq, xstr); | |
| /* Described in man terminfo as hpa=\E[%p1%dG */ | |
| strcat(essq, "G"); | |
| /* | |
| ** Execute the escape sequence | |
| ** This will move the cursor to x, y | |
| */ | |
| printf("%s", essq); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment