简体   繁体   English

交互输入未出现在C窗口中

[英]Interactive input that doesn't appear on the in the window in C

I'm writing a program that needs to ask the user a yes or no question at the end. 我正在编写一个程序,该程序最后需要询问用户是或否的问题。 Going based off the example .exe my teacher provided us, the line is supposed to print out "Would you like to print an Amortization Table(Y/N)?Y" and it looks for one keystroke from the user. 根据我的老师为我们提供的示例.exe,该行应打印出“您是否要打印摊销表(Y / N)?Y”,并从用户那里寻找一个击键。 The Y is printed out following the question like I typed, as it is supposed to represent the default choice so if the user presses [y] , [shift + y] , or [enter] it goes to the function that does the amortization table and if the user presses anything else it goes to the next line When it gets the input from the user it processes the keystroke instantly as it is pressed (it does not need [enter] to process the input) without letting the keystroke appear on the command prompt. Y会按照我输入的问题打印出来,因为它代表了默认选项,因此,如果用户按下[y][shift + y][enter]它将转到执行摊销表的函数如果用户按了其他任何键,则转到下一行。当从用户那里得到输入时,它会在按下时立即处理按键(不需要[enter]来处理输入),而不会让按键出现在屏幕上。命令提示符。 I have tried all the functions I can think of to do this (getc, getchar, getche) but everything I have tried ends up printing the user's input. 我已经尝试过可以想到的所有功能(getc,getchar,getche),但是我尝试过的所有操作最终都会打印出用户的输入。 Does anyone know what function he used or what trick he is doing to keep the keystroke from appearing in the command prompt? 有谁知道他使用了什么功能或他在做什么技巧,以防止击键出现在命令提示符下? Thanks for your help in advance, I am obviously new to programming. 感谢您的事先帮助,我显然是编程新手。

For the Windows platform, use the _getch() function from <conio.h> to read a keypress without buffering or echo. 对于Windows平台,请使用<conio.h>_getch()函数读取按键,而无需缓冲或回显。

Read the function description on MSDN 阅读MSDN上功能描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM