在C语言中什么是getch()函
getch()的原型为 int _getch();
所在的头文件为
在MSDN中是这样对getch()解释的:
The _getch function reads a single character from the console without echoing。
简单地说就是从缓冲区读取一个字符而不在输入设备上输入。它的返回值是它读取的字符的 ASCII码, 是一个int 值。不返回错误(原文为:_getch return the character read。 There is no error return。)
至于有什么用,这个是见仁见智的:因为它不在输出设备上显示,所...全部
getch()的原型为 int _getch();
所在的头文件为
在MSDN中是这样对getch()解释的:
The _getch function reads a single character from the console without echoing。
简单地说就是从缓冲区读取一个字符而不在输入设备上输入。它的返回值是它读取的字符的 ASCII码, 是一个int 值。不返回错误(原文为:_getch return the character read。
There is no error return。)
至于有什么用,这个是见仁见智的:因为它不在输出设备上显示,所以也有用在"Press any the to continue/quit"的。
下面是MSDN给的一个例子,希望对你有所以帮助:
/* GETCH。C: This program reads characters from
* the keyboard until it receives a 'Y' or 'y'。
*/
#include
#include
void main( void )
{
int ch;
_cputs( "Type 'Y' when finished typing keys: " );
do
{
ch = _getch();
ch = toupper( ch );
} while( ch != 'Y' );
_putch( ch );
_putch( '\r' ); /* Carriage return */
_putch( '\n' ); /* Line feed */
}
/*
Output
Type 'Y' when finished typing keys: Y
*/。
收起