如何检查"退格"字符用C

编程入门 行业动态 更新时间:2024-10-24 04:51:41
本文介绍了如何检查"退格"字符用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道如何检查,如果用户键入退格字。

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的是的使用残培()输入。我跑了一个小测试程序和残培()返回1​​27,当你点击退格键。因此尝试:

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

本文发布于:2023-05-25 10:54:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/226607.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   QUOT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!