getch()
函数从键盘上读取一个字符。它不使用任何缓冲区,所以输入的数据不会显示在输出屏幕上。getche()
函数从关键词中读取一个字符,但数据会显示在输出屏幕上。按Alt+f5可以看到输入的字符。
让我们看一个简单的例子 -
#include<stdio.h>
#include<conio.h>
int main()
{
char ch;
printf("Enter a character ");
ch=getch(); // taking an user input without printing the value.
printf("value of ch is %c",ch);
printf("Enter a character again ");
ch=getche(); // taking an user input and then displaying it on the screen.
printf("value of ch is %c",ch);
return 0;
}
运行结果如下:
Enter a character
value of ch is a
Enter a character again a
value of ch is a
在上面的例子中,通过getch()
函数输入的值不显示在屏幕上,而通过getche()
函数输入的值却显示在屏幕上。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。