Cannot get _kbhit to work anymore on windows, issue with conio

363 views Asked by At

Compiling Microsoft's sample program in C for using _kbhit thows me this error:

fatal error: conio.h: No such file or directory

I use Code::Blocks and GNU GCC compiler, and Windows 10.

The weird thing about that is, that this code worked 2 months ago.

I remember I was advised to use conio and _kbhit from here and here

conio.h issue

Why does conio throws me an error? Do I need to include something else? Isnt it standar C library?

1

There are 1 answers

1
igroglaz On

Which GNU GCC compiler? Cygwin or MinGW? Cygwin doesn't have 'conio.h' while MinGW got it. So it might be that you used in the past MinGW and everything worked, and then moved to Cygwin (I myself also had such migration).

In general native Linux GCC doesn't support 'conio.h' because GCC is Linux-bases compiler, while 'conio.h' is ancient DOS library. To be able to use 'conio.h' be sure to compile the code with MinGW GCC or Windows-based compilers (eg Embarcadero C++ Builder or Visual Studio C/C++ where 'conio.h' still exists).

Also it might be a good idea to use NCurses library instead which exists in GCC and provide similar functions as conio.h (and even better); though there is no kbhit() function - you need to to implement it yourself (eg http://www.flipcode.com/archives/_kbhit_for_Linux.shtml )