Sunday, 15 September 2013

c program to draw lines with arrow keys


#include<stdio.h>
#include<conio.h>

#define LKEY 75
#define RKEY 77
#define UKEY 72
#define DKEY 80

#define ACROSS 205
#define UPDOWN 186

int main()
{
char ch;
int x=40,y=12;
clrscr();

gotoxy(x,y);

while((ch=getch())==0)
{
switch( getch() )
{
case LKEY :x--;ch=ACROSS;break;
case RKEY :x++;ch=ACROSS;break;
case UKEY :y--;ch=UPDOWN;break;
case DKEY :y++;ch=UPDOWN;break;
}
gotoxy(x,y);
putch(ch);
}

getch();
return 0;
}

No comments:

Post a Comment