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

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Wojciech Guzinski
Solved:
2019-10-23
Last query:
2019-10-23
Last reply:
2019-10-22
Manfred Hampl (m-hampl) said : #1

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

https://www.tutorialspoint.com/kbhit-in-c-language

Wojciech Guzinski (wojtekg) said : #2

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

NAME
       kbhit - check for key-stroke

SYNOPSIS
   C function :
       #include <graphics.h>

       int kbhit (void);

   Scheme procedure :
            (kbhit)

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

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

   Example:
       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.

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

SEE ALSO
       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:
DESCRIPTION :
       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.