Javatpoint Logo
Javatpoint Logo

Conio.h in C

We will learn about the extremely helpful conio.h header file in C in this essay. We will also examine the functions contained in conio.h as well as the usage of conio.h in the C programming language.

What in C programming is conio.h?

The most common type of header file used in the C programming language. For console input-output, it is an acronym. C program use a lot of the built-in library functions in conio.h for input and output. From one compiler to the next, different functions may be defined inside the conio.h file.

Why is conio.h used in C?

Conio.h is a header file with several built-in functions that are commonly used to execute input/output on the console, or to receive input from the user's keyboard and show results on the screen. Several of the conio.h routines, such getch(), are used to retain the screen until the user presses a key.

Function Declared in the C file conio.h

The conio.h header files contain a number of functions, some of which include:

  • clrscr()

The output on the screen can be cleared with this function.

CODE:

Output

Output After using clrscr() function
????????????????????..
Process executed in 1.11 seconds
Press any key to continue

Explanation:

Here, in the code above, we have utilized the clrscr() function before printing two statements and included the two header files stdio.h and conio.h. Hence, all of the statements above the clrscr() method are cleared.

  • getch()

The keyboard reads one character. It prevents character echoes. The window should stay open until the user enters anything before proceeding or closing the application.

CODE:

Output

Enter your character: Press any key to continue
????????????????????????????
Process executed in 1.22 seconds

Explanation:

The two header files stdio.h and conio.h have been included in the code above, and after printing one line to solicit input from the keyboard, we utilized the getch() method, which will wait until the user stops entering data.

  • getche()

It is somewhat comparable to getch(), except it also supports alphanumeric values. It simultaneously publishes the character that is provided as input and echoes the character on the screen.

CODE:

Output

Enter your character: j Press any key to continue.
????????????????????????????
Process executed in 1.22 seconds

Explanation:

So, in the code above, we've included the header files stdio.h and conio.h, written one line that displays user input, and then used the function getche() to take an alphanumeric character and print it on the screen or console at the same time.

  • putch()

It prints out or displays a character on the console or screen.

CODE:

Output

j Press any key to continue.
????????????????????????????
Process executed in 1.22 seconds

Explanation:

Using the two header files stdio.h and conio.h, we first placed a character in a string variable. Then, we used putch() and handed the variable to it, which prints the character on the screen. This is the identical operation that was performed in the getch() method.

  • cgets()

It accepts a string of characters as input from the console until a carriage-return (CR) and linefeed are received (LF). The new line effect (n) results from combining both. Hence, the null terminator (O) at the end of the string is used to replace these CR/LF characters.

CODE:

Output

Input the character: Welcome to JavaTpoint
Output on the screen: Welcome to JavaTpoint 
???????????????????????????.
Press any key to continue.
Process executed in 0.11 seconds

Explanation

Here, in the above code, we have included the two header files stdio.h and conio.h then we has made a variable s of size 100 and an str variable to store the input value and then use to print it. After that, we have cgets() to input a string and then we have stored in it a variable s and then at the last statement we have print the value.

  • cputs()

It displays every character string on the output screen or terminal.

CODE:

Output

Welcome to JavaTpoint.
???????????????????????????.
Press any key to continue.
Process executed in 0.11 seconds

Explanation:

Here, in the above code we have included two header files stdio.h and conio.h then we has used cputs to print a string which displays the string on the console.

  • cscanf() and cprintf()

Both of them operate similarly to scanf() and printf (). Scanf() prepares user-provided input from the console, and printf() does the same for the string before printing the formatted string to the console or screen.

Output

Enter your marks: 80 
Passed, 80 
???????????????
Press any key to continue
Process executed in 1.11 seconds

Explanation

Here, in the code above, we have included two header files: stdio.h and conio.h. Then, we have taken a variable of the string data type, named marks, and it has a size of 50. Next, we have used the cprintf() function to print a line, the cscanf() function to collect user input, and the cprintf() function once more to print a string on the console.

  • kbhit()

This feature enables us to determine whether or not a user has depressed any keys. To determine if the player has pushed any keys or not, it is utilized in numerous games.

CODE:

Output

To stop this loop press any key
To stop this loop press any key
To stop this loop press any key
... Until the key is pressed
??????????????????
Press any key to continue
Process executed in 1.11 seconds

Explanation:

The kbhit() method was used in a while loop in the code above after two header files, stdio.h and conio.h, were included. Hence, the kbhit() method will continue the loop until and unless a key is touched, at which point it will stop and the program will end.

  • delline()

This feature is used to delete a line or several lines from the screen.

CODE:

Output

Welcome to JavaTpoint
Due to the delline function being used below, this line will be cleared.
Text printed after using delline function.
??????????????????????????.
Press any key to continue
Process executed in 1.11 seconds

Explanation:

Here, in the code above, we have included two header files: stdio.h and conio.h. After that, we have printed two lines, used the delline function to clear the line immediately above it, and then printed one line once more to show the result of the function's execution.

  • gotoxy()

The way this method operates is that it takes two arguments and then moves your cursor to a certain point on your window using those two parameters.

CODE:

Output

The cursor position has been changed.
...................................................................
Process executed in 1.11 seconds
Press any key to continue.

Explanation:

The two header files stdio.h and conio.h have been included in the code above, and after that, we have chosen two integer values and supplied them as a parameter to the function gotoxy(), which will modify the cursor location once the program has run.

  • wherey() and wherex()

This function provides information about the cursor's X and Y coordinates as of right now wherey() gives the y-coordinate of the cursor in the current output screen, whereas wherex() reveals the cursor's x-coordinate in the current output screen.

CODE:

Output

The Coordinates of X and Y are- (1,2)
...................................................................
Process executed in 1.11 seconds
Press any key to continue.

Explanation:

The two header files stdio.h and conio.h were included in the code above before we took two integers, x and y, and saved the values of wherex() in x and wherey() in y. Next, we printed the values of x and y, which indicated the current x and y coordinates of the pointer on the active screen.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA