What is the function of getch (); and the conio.h library?

5

What is the getch(); function used for?

What is the library for conio.h; what is the utility?

For example in a code type this:

#include <stdio.h>
#include <conio.h>

int main()
{
    printf("Hello world");
    getch();
    return 0;

}
    
asked by anonymous 12.11.2017 / 01:05

1 answer

2
The getch () as well as getche () returns the typed key, often used in switch menus. (Difference between the two is that getch () does not show the key you typed on the screen, but getche () shows the keystroke on the screen)

Files with .h extension are not libraries, but header files where, among other things, the prototype functions are used.

conio.h is for drawing screen, and is for / windows (conio functions are useful for manipulating characters on the screen, specifying character color and background.)

Now you must be asking yourself:
But what functions can I use with conio.h and what is the relation with getch ()?

The typical functions used with conio.h are clrscr (to clear the screen), gotoxy (position cursor on screen at x and y coordinates) getch (reads a keyboard character and does not show it on the screen), kbhit (tests if any key was pressed, you need to use getch getche before), delline (delete the line containing the cursor and move all the lines below it a line up), textcolor text color), textbackground (change the background color), cprintf (used to print on-screen color texts, you must specify the color using the textcolor function) / p>

In the case of your code the use of conio was due to the use of getch () .
Greater use of conio is because of getch, the other commands usually you can use the system () command that will use DOS command for the same purposes.

    
13.11.2017 / 13:51