
- kbhit函数不能运行,也不知道是什么原因导致的,怎么才能停止报错
因为getch()函数和kbhit()函数的头文件<conio.h>没有导入;
然后,再把input变量定义一下;
最后,如果只是需要通过按键来控制图形输出,scanf()那里可以改为input=getch(),那个if也可以去掉。
修改如下:
参考链接:
kbhit函数(讲解)__kbhit()_嘿克不黑的博客-CSDN博客
函数简介函数名:kbhit()(VC++6.0下为_kbhit())功 能及返回值: 检查当前是否有键盘输入,若有则返回一个非0值,否则返回0用 法:int kbhit(void);包含头文件: include <conio.h>程序示例 C语言#include<stdio.h>#include<conio.h>intmain...
https://blog.csdn.net/weixin_44350205/article/details/105667160
#include <stdio.h>
#include <windows.h>
#include <conio.h> // 加上getch()函数和kbhit()函数的头文件
int main(void){
int i,j;
int x=5;
int y=5;
char input;
while(1){
system("cls");
for(i=0;i<x;i++){
printf(" * \n");
}
for(j=0;j<y;j++){
printf("*****\n");
}
printf(" * * \n");
// scanf("%c",&input); // 这个可以去掉
// https://blog.csdn.net/weixin_44350205/article/details/105667160
input=getch();
if(input=='w'||input=='W') y--;
if(input=='a'||input=='A') x--;
if(input=='s'||input=='S') y++;
if(input=='d'||input=='D') x++;
}
return 0;
}
