undefined symbol kbhit() and printf()

prototype of a function in c++ is mandatory to give.........but when we give the prototype of the function then there are alot of errors.....

see ex


int printf(const char*,...);
int scanf(const cahr*,...);
int kbhit(void);
void clrscr(void);
int main(void)
{
clrscr();
printf("hello");
while(!kbhit());
return 0;
}


file extension must be .cpp


when file extension is .c or any extension except .cpp then this program gives output hello......

if u know then plz ans.........
The prototype only tells the current context that a specific function exists, and what it looks like. However, if you do not either:
1) provide a definition for the function in your code, or
2) link your code with an already compiled version of the function
then the compiler will complain.

Both printf() and scanf() are C standard library functions found in <cstdio> for C++ or <stdio.h> for C.

The clrscr() and kbhit() functions are old Microsoft routines found in various places, but most commonly in <conio.h>. If your compiler supprts it then you should use a modern equivalent. If you are using Windows, choose one of the following to replace kbhit():
http://www.cplusplus.com/forum/general/3389/#msg14326 (== kbhit)
http://www.cplusplus.com/forum/beginner/5619/#msg25047 (== kbhit with delay timeout)
To clear the screen, see my article: http://www.cplusplus.com/articles/4z18T05o/

Once you #include the proper header files, you do not need to prototype the functions yourself (the header file does that for you).

Hope this helps.
thanx for the reply sir ........


i already know that printf(),scanf(),kbhit() these are standard run time library defined function..........


but i use turbo TCPP IDE and I do not get <cstdio.h> for c++...........so plz help me out of this......
There is no such file as <cstdio.h>.
All the ones I listed for you are required by the language, so if your compiler is a valid C or C++ compiler, it will support them.
Last edited on
Topic archived. No new replies allowed.