A really annoying Dev C++ error

Uuplaku

Member
Oct 12, 2001
122
0
0
First off, here's the source code:

#include <stdio.h>
#include <conio.h>

void main()
{
for(;;)
{
printf("PLAY ME!!", '\x20');
if(kbhit())
{
break;
}
}
}

Whenever I try to compile it under Dev C++, I always get this annoying error message:

implicit declaration of function `int kbhit(...)'

Dandgit, how can I get rid of this problem?
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Well you might pay attention to the compiler, it's telling you that "kbhit()" has not been declared.

So, you could think to yourself: "Hmmm....this is supposed to be in the console library! what's up? why does the universe hate me? Aaaaaahhhhh!!!!!!"

Sorry. You could think to yourself:
1. Did I #include the right library?
2. Did I type the function name correctly?
...and both of these thoughts should prompt you to check the library docs.

You don't list compiler or OS, but for VC++ the function name starts with an underscore '_'

Help > Index is your friend, it isn't sarcastic like me :)
 

Uuplaku

Member
Oct 12, 2001
122
0
0
To answer your questions:

#1: Yes, the kbhit function is lsited in the conio.h header
#2: Yes, I checked through the actual header and it listed that correct spelling.

Compiler: Dev C++ (hence the title)
OS: Windows XP Pro

Im thinking that it might've happened because Im using some antiquated C formatting, and Im unfamiliar with how you're supposed to do this in C++.
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
Your code cut and paste just fine into Vc++ and compiled in a virgin project. I suspect you have some define's wrong which are preventing the compiler from actually finding the declaration, why don't you create a new console project (I assumed your old one was a console project and not a win32 app) and paste this in.

Bill
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
To put what bsobel[i/] said in a student style instruction:

Start a brand new project.

Paste in the source code to the source file.

Run the compiler and linker and you should be OK.

You have probably affected a setting on your development configuration. If the setting is project dependent, starting with a clean project will solve the problem.

If you have affected the configuration of the development environment, you will have to identify the change made or do a clean sweep (remove the existing environment completely and re-install your development system.