Thread: (!_kbhit()) problem in Dev-C++

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    at the bottom of the tank
    Posts
    6

    (!_kbhit()) problem in Dev-C++

    I was looking over some code put together by Harpreet Singh Juneja and tried to compile it to see what happens. I get these two errors:

    90 d:\portsp~1\hsport.cpp
    implicit declaration of function `int _kbhit(...)'

    102 d:\portsp~1\hsport.cpp
    implicit declaration of function `int _getch(...)'

    I am thinking that the problem is this was done in VC++ and I am using Dev-C++.

    here is the part with the problem:

    Code:
    	
    			if (strlen(buffer) > 2)					/* we have a wait specification */
    				{	
    					hsport.token(&buffer[1],&token_ptr);
    					if (token_ptr != NULL)				/* if pattern specified */
    					{	
    						sscanf(token_ptr,"%x",&match_byte);
    						printf("Waiting for byte %4.4x.  Hit any key to terminate\n",match_byte);
    						hsport.rdport();
    						while (!_kbhit())
    						{
    							save_byte = hsport.getbyte();
    							hsport.rdport();
    							if (hsport.getbyte() == match_byte)
    							{
    								printf("Pattern %4.4x found, hit any key.\n",hsport.getbyte());
    								hsport.setbyte(save_byte);
    								break;
    							}
    							hsport.setbyte(save_byte);
    						}
    						_getch();	/* clears the port */
    					}
    				}
    so how should it be fixed?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Perhaps the library that comes with Dev-C++ has kbhit and getch without the underscores. Did you #include <conio> or <conio.h> or <conio.c>? There are a lot of platforms where at least one of those works.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    You need to include <conio.h> to use _kbhit(). I use _kbhit at the end of my console programs.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> You need to include <conio.h> to use _kbhit(). I use _kbhit at the end of my console programs.

    In Dev-C++?

  5. #5
    Registered User
    Join Date
    Jun 2007
    Location
    at the bottom of the tank
    Posts
    6
    here are the results:
    <conio> ; no such...
    <conio.c> ; 31 errors
    <conio.h> ; same two errors as original
    delete underscore ; more of same type of errors showed up, deleted all underscores. one error left. 91 d:\portsp~1\hsport.cpp
    implicit declaration of function `int kbhit(...)'
    Code:
    while (!kbhit()

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I found this in a search: http://cboard.cprogramming.com/showthread.php?t=16550

    What version of Dev-C++ do you have? Maybe upgrading to 4.9.9.2 will help if you don't have the latest.

  7. #7
    Registered User
    Join Date
    Jun 2007
    Location
    at the bottom of the tank
    Posts
    6
    is there another way to do the same thing? (without the errors)

  8. #8
    Registered User
    Join Date
    Jun 2007
    Location
    at the bottom of the tank
    Posts
    6
    By the way, I can't the search on this forum. it times out every time.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    It often helps to do a more specific search when that happens.

    You can't do exactly that without using some non-standard function or another. What are you trying to do?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  2. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  3. Problem running prog I wrote in Dev C++
    By KidMan in forum C Programming
    Replies: 8
    Last Post: 09-22-2005, 01:50 AM
  4. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM