求解c语言关于getch 和getchar
程序代码:#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
int i,j;
void xianshiditu(int ditu[10][12]); //申明界面函数
void yanse(int b); //颜色函数
int main ()
{
char input;
int fenshu=0; //定义分数变量 用来判断游戏结束
int ditu[10][12]={
{2,2,2,2,2,1,1,1,1,1,2,2},
{1,1,1,1,2,1,0,0,0,1,1,2},
{1,0,0,1,1,1,0,1,0,0,1,2},
{1,0,4,3,3,3,3,3,1,0,1,1},
{1,0,0,1,1,3,3,3,4,0,0,1},
{1,0,0,0,0,4,1,1,4,1,0,1},
{1,0,4,1,4,0,0,0,4,0,0,1},
{1,1,0,6,0,1,1,1,4,1,0,1},
{2,1,1,1,1,1,2,1,0,0,0,1},
{2,2,2,2,2,2,2,1,1,1,1,1}
};
while(1)
{
system("cls");
printf("c语言推箱子游戏\n");
xianshiditu(ditu);
printf("当前分数为:%d \n",fenshu);
for(i=0;i<10;i++)
{
for(j=0;j<12;j++)
{
if (ditu[i][j]==6||ditu[i][j]==9)
break;
}
if (ditu[i][j]==6||ditu[i][j]==9)
break;
}
printf("你当前位置 (%d,%d)\n");
input=getch(); //用来控制人移动,不用回车
switch (input)
{
case 'w': //上移
if (ditu[i-1][j]==0&&ditu[i-1][j]==3)
{
ditu[i-1][j]=+6;
ditu[i][j]=-6;
break;
}
if (ditu[i-1][j]==4||(ditu[i-2][j]==0&&ditu[i-1][j]==3))
{
}
break;
}
}
return 0;
};
void xianshiditu(int ditu[10][12])
{
for(i=0;i<10;i++)
{
for(j=0;j<12;j++)
{
switch (ditu[i][j])
{
case 0:
printf(" "); break; //路
case 1:yanse(12);
printf("※"); break; //墙
case 2: printf(" "); break; //界面外部空地
case 3: yanse(11);
printf("☆"); break; //目的地
case 4: yanse(9);
printf("□"); break; //箱子
case 6: yanse(13);
printf("△"); break; //人
case 7: yanse(10);
printf("■");break; //箱子与目的地重合
case 9: yanse(18);
printf("▲"); break; //人在目的地
}
}
printf("\n");
}
}
void yanse(int b) //颜色函数
{
HANDLE hConsole=GetStdHandle((STD_OUTPUT_HANDLE));
SetConsoleTextAttribute(hConsole,b);
}错误 1 error C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details. e:\vc2012\测试\测试\测试.c 44
为什么getch不能用但是换getchar就行







