我正在Windows XP中的Code :: Blocks中運行一個C程序。 我得到一個錯誤爲什麼getch()在C中拋出一個錯誤
"drawing operation is attempeted when there was no current window"
什麼可能會導致這樣,我該如何解決呢? 我的代碼如下:
#include <stdio.h>
#include <conio.h>
static int get_code(void);
// System dependent key codes
enum
{
KEY_ESC = 27,
ARROW_UP = 256 + 72,
ARROW_DOWN = 256 + 80,
ARROW_LEFT = 256 + 75,
ARROW_RIGHT = 256 + 77
};
int main(void)
{
int ch;
puts("Press arrow keys, escape key + enter to exit:");
while ((ch = get_code()) != KEY_ESC)
{
switch (ch)
{
case ARROW_UP:
printf("UP\n");
break;
case ARROW_DOWN:
printf("DOWN\n");
break;
case ARROW_LEFT:
printf("LEFT\n");
break;
case ARROW_RIGHT:
printf("RIGHT\n");
break;
}
}
getchar(); // wait
return 0;
}
static int get_code(void)
{
int ch = getch(); // Error happens here
if (ch == 0 || ch == 224)
ch = 256 + getch();
return ch;
}
@Vlad http://www.programmingsimplified.com/c/conio.h/getch –
是的,它是conio.h –
@RasmiRanjanNayak你有'conio.h'庫安裝? –