kbhit() probkem

Asked by Wojciech Guzinski on 2019-10-20

man kbhit shows:
       #include <graphics.h>

       int kbhit (void);
Why compilation failed?
undefined reference to `kbhit()'

Question information

English Edit question
Ubuntu Edit question
No assignee Edit question
Solved by:
Wojciech Guzinski
Last query:
Last reply:
Manfred Hampl (m-hampl) said : #1

From where did you get that manpage for kbhit? It seems wrong.


Wojciech Guzinski (wojtekg) said : #2

Ubuntu graphics prowide it's own kbhit , here you are man page:
KBHIT(3) SDL-libgraph API KBHIT(3)

       kbhit - check for key-stroke

   C function :
       #include <graphics.h>

       int kbhit (void);

   Scheme procedure :

       kbhit() checks to see if a keystroke is currently available.

       Any available keystroke can be retrieved using getchar(3) or getch(3).

       while(!kbhit()) /* Loops until a key is pressed */

       This function can be used both in graphics mode and plain text. For
       other functions related to textmode see graphicstext(3)

   Note :
       In text mode use getchar(3) (not getch(3)) to retrieve the keystroke
       since getch(3) flushes the input buffer before reading.

       On success (if a keystroke is available) kbhit() returns the keystroke.
       If a keystroke is not available it returns 0.

       libgraph(7), initgraph(3), getchar(3),
       getch(0), graphicstext(3)

libgraph-1.x.x 11 AUGUST 2003 KBHIT(3)

Manfred Hampl (m-hampl) said : #3

Don't blame Ubuntu for broken foreign software.
Ubuntu does not contain libgraph, so "Ubuntu graphics prowide it's own kbhit , here you are man page:" can't be true.

Manfred Hampl (m-hampl) said : #4

Reading your other questions on Launchpad and following the links in them, it seems to me that the KBHIT(3) man pages that you quoted are part of http://download.savannah.gnu.org/releases/libgraph/libgraph-1.0.2.tar.gz
Definitely not part of Ubuntu.

Wojciech Guzinski (wojtekg) said : #5

OK, this is the only, I know, graphics library working with ubuntu, it woks perfect just this one function can't be used.
This is minor problem I just asked if anyone knows why.

Manfred Hampl (m-hampl) said : #6

Haven't you read my comments and the links provided?

https://www.tutorialspoint.com/kbhit-in-c-language explains that kbhit() needs "#include <conio.h>"

https://askubuntu.com/questions/525051/how-do-i-use-graphics-h-in-ubuntu describes other and more current graphics libraries, e.g. OpenGL (via GLUT) and libxbgi.

Wojciech Guzinski (wojtekg) said : #7

I know that regular (not graphics) programming require conio.h and stdio.h but man pages mislead me.
in man pages (grapicstext) is told that some i/o funttions are "hacked" for working in libgraph window:
       These are the normal scanf(3), printf(3), getchar(3), putchar(3) func‐
       tions hacked up to work in graphics mode (i.e. in the libgraph window).
Also man page for kbhit says include grapjics.h

Manfred Hampl (m-hampl) said : #8

How often do I have to repeat:
The error is not in a piece of software from Ubuntu, but from elsewhere - https://savannah.nongnu.org/projects/libgraph/

Ubuntu cannot change foreign software, you have to report your problem there.

Wojciech Guzinski (wojtekg) said : #9

OK, thanks.