What is conio.h in C?

The conio.h is a header file that contains utility functions to perform input and output operations to the console from the C program. This header file is mostly used by MS-DOS compilers like Turbo C. The conio.h header file is compiler specific. So conio.h is not supported by GCC compiler. To write portable code that should work on multiple compilers, avoid using the functions of the header file.

The most commonly used functions are as follows:

  1. clrscr(): This clears the console.

  2. getch(): This reads a single character from the keyboard.

  3. getche(): This reads the next available keystroke from the console. It waits until a keystroke is available and prints the character on the console at the position of the cursor.

  4. putch(): This prints a character to the console at the current cursor location.

  5. gotoxy():This places the cursor at the desired location on the console

Code example

Let's look at the code below:

#include<stdio.h>
#include<conio.h>
int main()
{
printf(" Please enter character: ");
// get character from user
char ch = getch();
printf("\nPressed character is: ");
// print the character to the screen
putch(ch);
printf(" Please any character to clear the screen ");
getche();
// clears the screen
clrscr();
printf(" Please enter character: ");
int x = 100, y = 100;
//Places the cursor at (x,y) position on the console
gotoxy(x, y);
printf("Printed in 100,100 coordinates of the screen");
getch(); /* Holding the program */
return 0;
}

Code explanation

  • Line 8: We use the getch() method to get a character as input. And store the provided input character to a char variable ch .

  • Line 12: We use the putch() method to print the character ch to the output console.

  • Line 14: We ask the user to input any character to clear the screen. This is done so that the program will wait until the user enters a character. Once the user enters a character, the clrscr() method in line 17 is used to clear the console.

  • Line 21: We create two integer variables, x and y, and assigned the value 100 to both of the variables.

  • Line 23: We use the gotoxy() method to move the cursor to specific coordinates of the console. We pass x and y as an argument to the gotoxy() method. So the cursor will be at 100,100 coordinates.

  • Line 25: We use the printf() method to print a message to the console. Now the cursor is in the 100,100, and the message will start from there.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved