我想知道如何检查,如果用户键入退格字。
I'd like to know how to check if a user types the "backspace" character.
我用在我的C程序中的的getch()函数,即键=残培(),我想检查时,退格为pressed。行:
I'm using the getch() function i.e. "key = getch()" in my C program and i'd like to check when backspace is pressed. the line:
if(key = '\b') { ....不起作用。
推荐答案有阅读问题退格是,大多数终端像退格由终端驱动程序处理的键熟。不过,诅咒功能残培()可以阅读退格,因为它是不依赖于终端。
The problem with reading Backspace is that most terminals are 'cooked' in that keys like backspace are handled by the terminal driver. However, the curses function getch() can read the backspace as it's not tied to the terminal.
我只注意到你的code的是的使用残培()输入。我跑了一个小测试程序和残培()返回127,当你点击退格键。因此尝试:
I just noticed your code is using getch() for input. I ran a little test program and getch() returns 127 when you hit backspace. Therefore try:
if (key == 127 || key == 8) { ... /* Checks for both Delete or Backspace */另外请注意,您的样本code使用分配运营商 = 时,它应该使用的平等运营商 ==
Also note that your sample code uses the assignment operator = when it should be using the equality operator ==
更多推荐
如何检查"退格"字符用C
发布评论