Home>Article>Backend Development> What is the function of getch()

What is the function of getch()

青灯夜游
青灯夜游 Original
2021-01-13 13:58:59 29232browse

The function of getch() is to read a character from the console but not display it on the screen; when the user presses a character, the function automatically reads it without pressing Enter. The syntax format is "int getch(void)". When using getch(), you need to introduce the header file "conio.h".

The operating environment of this article: Acer S40-51, Dev-C version 5.11, Windows10 Home Chinese version

Related recommendations:C language video tutorial,C Video Tutorial

getch() is a function used in programming. This function is a non-echo function. When the user presses a certain character, the function automatically reads it without Press Enter. Some C language command line programs will use this function to make games, but this function is not a standard function, so pay attention to portability!

getch():

is located in the header file: conio.h

Function purpose: Read a character from the console, but not displayed in On the screen

Function prototype: int getch(void)

Return value: Read characters

For example:

# include  # include  int main() { char ch; printf("请输入一个字符: "); ch = getch(); //在输入字符的时候,屏幕上并看不到输入的字符 printf("输入的字符是:%c ",ch); //输出字符 return 0; }

What is the function of getch()

Explanation:

getch(); is not a function in standard C and does not exist in C language. Therefore, pay attention to the portability of the program when using it. Domestic C language novices often use getch(); to pause the program and do not know the source of this function. It is recommended to use getchar() or use system("PAUSE") in the header file to call the system command to pause; (if If circumstances permit) replace this function or replace a compiler.

For more programming-related knowledge, please visit:Programming Learning! !

The above is the detailed content of What is the function of getch(). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn