程序的方向赋值设置了条件,为什么赋值上后还是能赋值为下,求解答
#include<stdio.h>#include<conio.h>
char tou;
enum FX
{
up = 72, down = 80, left = 75, right = 77
};
void changfx_()
{
char key;
if ((key = _getch()) < 0)
{
key = _getch();
}
switch (key)
{
case up:
if (key != down)
tou = up;
break;
case down:
if (key != up)
tou = down;
break;
case right:
if (key != left)
tou = right;
break;
case left:
if (key != right)
tou = left;
break;
}
}
int main()
{
while (1)
{
changfx_();
printf("方向为=%d\n", tou);
}
}