我想使用箭头键在C中的屏幕上的符号周围移动

时间:2019-12-09 17:38:32

标签: c

#include<stdio.h>
#include<conio.h>
#include<windows.h>
void gotoxy(short x, short y);    //here we declare the gotoxy function//
main()
int x=1,y=1;
{   
 gotoxy(x,y);                      //now where we want to call  gotoxy function //
 printf("*");

}
 return 0;
}
void gotoxy(short x, short y)           //definition of gotoxy function//                                               
{
 COORD pos ={x,y};
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);

这是我到目前为止所拥有的。 但是我想这样做,所以当我使用箭头键时,它会通过朝着按下键所指向的方向移动一个空间来重新定位自己的位置

1 个答案:

答案 0 :(得分:0)

使用getch()时,应用程序将暂停直到按下某个键。有关箭头键的用法,请参见链接。然后根据所按的箭头从全局x和y变量中添加或减去。然后调用gotoxy函数。 并在发布问题之前检查您的语法。