Home »
C programs »
conio.h header file functions
gotoxy() and kbhit() functions of conio.h in C
In this article, we are going to learn about the two rare pre-defined functions (gotoxy() and kbhit()) of conio.h header file.
Submitted by Manu Jemini, on March 15, 2018
<conio.h> - gotoxy() function in C
If you want to take your cursor on a particular coordinate on the window, then gotoxy() function is made for you. What it takes from you are two parameters.
The Integers should be the x and y coordinate of the console. This is pretty helpful for games and animations. The Integers should be passed when you call the function in your program.
gotoxy() function Example in C
#include <stdio.h>
// to use 'gotoxy()' and 'getch()'
#include <conio.h>
int main() {
// define the type of variables
int a, b;
// define the value of variables
a = 50;
b = 30;
// change cursor position on further co-ordinates.
gotoxy(a, b);
// message
printf("The position of cursor is changed");
// for killing the execution
getch();
return 0;
}
<conio.h> - kbhit() function in C
On the other side kbhit() function is quite simple and not usually come handy. What this function do is, it tells us if a user has pressed any key or not. Again, this is very useful in games or if you want to show something else while your user is not pressing any key.
These functions are from the conio.h file and should include that file in your program.
kbhit() function Example in C
#include <stdio.h>
// to use 'kbhit()'
#include <conio.h>
int main() {
// for running the process until condition gets true
do {
// message
printf("Press any key from keyboard to kill or stop the process\n\n");
} while (!kbhit());
return 0;
}
Output