在C语言中什么是getch()函数?
答案:1 悬赏:40
解决时间 2021-10-10 07:52
- 提问者网友:佞臣
- 2021-10-10 00:27
在C语言中什么是getch()函数?
最佳答案
- 二级知识专家网友:过活
- 2021-10-10 01:23
getch()的原型为 int _getch();
所在的头文件为 <conio.h>
在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给的一个例子,希望对你有所以帮助:
#include <conio.h>
#include <ctype.h>
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' );
_putch( '\n' );
}
所在的头文件为 <conio.h>
在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给的一个例子,希望对你有所以帮助:
#include <conio.h>
#include <ctype.h>
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' );
_putch( '\n' );
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯