In this article, we will discuss one of the most important header files in C which is conio.h. We will also study about the use of conio.h in C programming and some important function of < conio.h> header file (conio.h library functions), which is used to related” console/screen” programs. Full form of conio.h is “Console input-output”.
Introduction to Conio.h
conio.h is a header file that stands for “Console Input & Output”, it provides the function of console input and output. GCC compiler doesn’t support conio.h file, as we studied that it provides console input/output functions. so we will discuss some important functions that are used to clear the screen, hold the screen, changing the background color of the text.
Syntax to include
#include
Note: The GCC compiler doesn’t support conio.h file, which is provided by the Borland Turbo C compiler.
C < conio.h> Library Function
Some important function of < conio.h> library function:
Some more functions of conio.h header file is highvideo() (this function is used to brighten the character string and shows it on screen), movetext() (this is used to move the text which shows on screen), and some more functions are also there like gotoxy()(this function accept two arguments so it basically takes the cursor on the particular coordinate. so the first argument is the x coordinate and the second argument is the y coordinate, wherex(), tells us about the x coordinate of the cursor and wherey() tells us about the y coordinate of the cursor.
clrscr()
This < conio.h> header file function is used to clear the output screen
Code:
#include <stdio.h> #include <conio.h> int main() { printf(“Welcome”); printf(“\nScreen before use of clrscr”); clrscr(); printf(“Screen After use of clrscr() function”); return 0; }
Output:
Screen After use of clrscr() function
Explanation:
In the above c program we use < conio.h> header file function which is clrscr() , this function clears the screen, we observe on the output screen that the print statement
Before clrscr function has been clear. and print statement after clrscr function is coming on the output screen, This shows the clrscr () function of < conio.h> header file clear the output screen.
getch()
This < conio.h> header file function is used to hold the screen,here we want the window to wait for user input before terminating or continuing the program.
Code:
#include <stdio.h> #include <conio.h> int main() { printf(“Input the value”); getch(): return 0; }
Output
Input the value:
Explanation
In the above c program we use < conio.h> header file function which is getch(), this function here holds the screen, like if we observe that after print statement (“Input the value”), it prints on the output screen and getch() holds the screen,and if press any key then only the screen get a release or terminate.
getche()
This < conio.h> header file function is used to accept the alphanumeric values and simultaneously prints the character on the screen which is given as the input that
Echoes the character, it is similar to getch() function.
Code:
#include<stdio.h> #include <conio.h> int main() { printf(“Input the values”); getche(); return 0; }
Output
Input the value:
Explanation
In the above c program we use < conio.h> header file function getche(), which is similar to the getch() function but it also accepts the alphanumeric value and simultaneously prints on the console /output screen. so it holds and also prints on the screen before releasing the screen that is why it similar to the getch function because here also screen hold/wait happens.
putch()
This < conio.h> header file function is used to print or put a character on the screen/console.
Code:
#include<stdio.h> #include <conio.h> int main() { char k=’l’; putch(k); return 0; }
Output
l
Explanation
In the above c program we use < conio.h> header file for putch() function, basically, this function is used to print or put characters on the console, here we observe we have taken the char variable name as k, which is equal to ‘l’ after this we use putch function and pass the k variable. we observe on the output screen that character ‘l’ has been printed.
cgets()
This < conio.h> header file function is used to input a group of characters (string) from the console until it gets carriage return and linefeed.
Code:
#include <stdio.h> #include <conio.h> int main() { char s[100]; char *str; S[0] =50; printf(“Input the character:”); Str =cgets(s) printf(“\nOutput on the screen:%s”, str); return 0; }
Output
Input the character: welcome to college dekho
Output on the screen: welcome to college dekho
Explanation
The two header files stdio.h and conio.h have been included in the code above, and we’ve created a variable of size 100 called s and an str variable to hold the input value before printing it. After that, we use cgets() to enter a string, store it in a variable called s, and then output the value in the final statement
cputs()
This < conio.h> header file function is used to print the string (group of characters) on the console or output screen.
Code:
#include <stdio.h> #include <conio.h> int main() { cputs (“Welcome Prepbyes”) return 0; }
Output
Welcome Prepbytes
Explanation
In the above c program we use < conio.h> header file function for cputs() function (for printing whole string on console ), here we print the string (group of characters) which is “ WelcomePrepbytes” and we observe on output screen that “Welcome Prepbyes” has been printed.
textcolor()
This < conio.h> header file function is used to define text color.
textbackground()
This < conio.h> header file function is used to
Summary
"conio.h" is a C header file (a file containing function declarations) that provides console input/output functions for C programs. These functions allow for simple input and output operations, such as reading a single character from the keyboard or printing text to the console. Examples of functions provided by conio.h include "getch()" (to read a character from the keyboard without waiting for the Enter key to be pressed) and "clrscr()" (to clear the console screen). However, the conio.h header file is not a part of the standard C library and is specific to certain compilers and operating systems, so it may not be available on all systems.