본문 바로가기

Study/C C++

gcc , clrscr gotoxy

#include <stdio.h>

#include <string.h>

void clrscr(void) {

int i;

for (i = 0; i < 100; i++)

// A bunch of new lines for now. It's blank, hey!

putchar('\n');

}

int 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);

return 0;

}

/*

** Example

*/

int main () {

clrscr();

gotoxy(2, 0);

printf("Coordinates: x = 2; y = 0;\n");

gotoxy(5, 5);

printf("Coordinates: x = 5; y = 5;\n");

return 0;

}


http://www.daniweb.com/code/snippet64.html# 에서 발견하였습니다. 지금 gcc말고 다른컴파일러에서 만들어진것을

 
gcc로 한참 모방중이였습니다. 그런데 clrscr 하고 gotoxy가 gcc에서 지원이 안되는것을 알았습니다.
여러곳을 찾다가 man에서 curses를 알게되었는데, 여기 getxy인가 무슨 씨리즈 잇던데.. ;; 아직 내공이 부족한지

함수명(Window *win,int n, int y); 이게 무슨뜻인지 몰라서, 다른 방안을 찾다가 찾았습니다..휴

C ..;; 하면할수록 어렵지ㅠㅠ

'Study > C C++ ' 카테고리의 다른 글

윈도우 mfc bzero  (0) 2009.12.09
getch() for Linux  (0) 2009.07.03
kbhit() for Linux  (0) 2009.07.03
온라인 man  (0) 2009.07.02
Bool  (6) 2009.07.02
C언어, 랜덤함수 , 포인터  (2) 2009.06.20