[c] 커서 움직이기


#include<stdio.h>
#include<process.h>
#include<stdlib.h>
#include<windows.h>
#include <conio.h>

void gotoxy(int x, int y);
int main(){
 int x,y;
 int ch;

 x=40;
 y=10;
 system("cls");

while(1){
  gotoxy(x,y);
  putch('#');
  ch = getch();

  if(ch == 0xE0 || ch == 0 ){
   ch = getch();
   switch(ch){
    case 75:
     x = x-1;
     break;
    case 77:
     x=x+1;
     break;
    case 72 :
     y=y-1;
     break;
    case 80:
     y=y+1;
     break;
   }
  }else{
   switch(ch){
    case ' ':
     system("cls");
     break;
    case 'q':
    case 'Q':
     exit(0);
   }
  }
 }
 return 0;
}
void gotoxy(int x, int y)
{
 COORD Pos = {x-1, y-1};
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}

'and so on' 카테고리의 다른 글

모든 플라스틱이 위험한가?  (0) 2011.12.23
[C] delay함수  (0) 2011.09.16
[C] gotoxy()  (2) 2011.09.14
정재형 유희열 보컬대결  (0) 2011.05.10
집에서 일할 때 집중하라  (0) 2011.01.14