I have made a program that moves a dot around the screen. The program doesn't work right all the time(leaves dots on the screen) unless I have a certain gotoxy function in. When I look through the program, the function doesn't appear necessary, but it makes all the difference to my compiler.
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define ENTER '\r'
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
main()
{
int key,xval,yval;
xval=40;
yval=12;
key=0;
clrscr();
printf("Use the arrow keys to move the dot, ENTER to quit: ");
gotoxy(xval,yval);
printf("*");
while(key!=ENTER) {
key=getch();
if(key==0) /*this statement blocks other input*/
key=getch();
else
break;
gotoxy(xval,yval); /*this line is the key*/
printf(" ");
switch(key) { /*moving the cursor*/
case UP:
gotoxy(xval,--yval);
break;
case DOWN:
gotoxy(xval,++yval);
break;
case LEFT:
gotoxy(--xval,yval);
break;
case RIGHT:
gotoxy(++xval,yval);
break;
}
printf("*");
}
}
can anybody tell me why this happens??
p.s. are these tags good enough prelude?