Everything You Need to Know About Conio.h Library Functions in C/C++When writing any C code, we must include the stdio.h and conio.h header files. Have you ever thought why the code need these header files? There is a lot of publicly accessible data regarding the stdio.h header file and its functions, but programmers frequently have trouble locating information on the conio.h header file and its operations. Hence, in this post, students will find all of the conio.h library functions, example source code, and a conio.h header file instance. Let us begin with an introduction. In C/C++, what is conio.h?Conio is an abbreviation for Console-Input-Output. The conio.h header file is a non-standard header file that is used in C and C++ code. This file contains console input/output functions used primarily by MS-DOS compilers. We've gone through a few of the most significant and often used functions in the conio.h header file. Contents:
Functions in the conio.h header file: 1. clrscr():Function Declaration We can erase the output command window with this operation. We commonly display the code execution progress, mistake of information, and expected outputs from the command prompt. In order to clear the previous written information on the output console during code execution, use the clrscr() function. Code: 1. getch():Function Declaration This operation can be used to retrieve characters from the keyboard. This technique additionally serves to keep the output screen shown until the user inputs a character. If this technique is not used, the output screen disappears in a fraction of a second. Conio.h has a non-standard function called getch(), although getchar() is a standard c library function. Code: 3. getche():Function Declaration getche() is a method that is similarly to getch(). Just one distinction is that in the output window, this function additionally prints the value entered by the user. Code: Output Do you wish to continue?? Y or N Y 4. cgets():Function Declaration Read a string of characters from the console using this function. This method reads characters until it comes across carriage-return (CR) and linefeed characters (LF). At the conclusion of the string, the cgets() function replaces CR/LF with the null terminator (0). Code: 5. cputs()Function Declaration Use cputs() to display a character string to the output screen. The carriage-return and newline characters are removed from the string. It is unable to change newline character (n) to carriage return (r) and new-line character (n) combination. Code: Output Hi Folks 6. cscanf():Function Declaration The cscanf() function scans and analyzes console input. To read input in the desired format, a format specifier is supplied to the cscanf() method. When it reaches the end of the input stream, this method returns EOF. Note: The cscanf() function is used in the instance cprintf() code below.2. cprintf():Function Declaration The cprintf() function prints output values to the console based on the format specification. Code: Output Input a string value: JavaTpoint Inputted string value is: JavaTpoint 8. kbhit():Function Declaration kbhit(): When a key is pushed, it returns a non-zero value; else, it returns zero. Code: Output This code will continue to print "Pls enter a key" until the user enters a key. 9. textcolor():Function Declaration This function is used to change the colour of text. Code: Output Welcome to JavaTpoint 10. extbackground():Function Declaration This function is used to modify the colour of the text's background. Code: Output Welcome to JavaTpoint
To add the conio header file in the code, use the following syntax.
In C/C++ programming, the term 'include' refers to a pre-processor directive that allows programmers to import header files into their code. It also tells the compiler to perform these header files prior to compilation. Conclusion:That's all there is to it. We expect students now have a good understanding of the conio.h header file and the functions it provides.
Next TopicIncrement and Decrement Operators in C++
|