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 <conio.h> # include <stdio.h> int main() { char ch; printf("请输入一个字符: "); ch = getch(); //在输入字符的时候,屏幕上并看不到输入的字符 printf("输入的字符是:%c ",ch); //输出字符 return 0; }
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
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!