【问题标题】:How to check what the user set for erase/backspace in stty using c如何使用 c 检查用户在 stty 中为擦除/退格设置的内容
【发布时间】:2014-02-20 03:25:42
【问题描述】:

在 Unix 中,某些键的默认设置因平台而异。例如,在 Ubuntu 中擦除可能是 erase = ^?。但是,对于 AIX,它可能与示例 erase = ^H 完全不同。如何检查 C 中的 stty 设置?

这是我试图写的

#include<stdio.h>
#include<stdlib.h>
#include<termios.h>
#include<unistd.h>

int main()
{
  struct termios term;

  if(tcgetattr(STDIN_FILENO, &term) < 0)
  {
     printf("Error to get terminal attr\n");
  }

  printf("The value for Erase is %s\n",term.c_cc[ERASE]);

  return 0;
}

使用 gcc 编译后。它说 ERASE 未声明。那么我应该使用的正确选项或变量是什么?

【问题讨论】:

    标签: c linux termios stty


    【解决方案1】:

    printf("The value for Erase is %s\n",term.c_cc[ERASE]); 应为printf("The value for Erase is %d\n",term.c_cc[VERASE]);,更多详情请参阅termios(3)

    擦除字符的符号索引是VERASEc_cc[VERASE]的类型是cc_t,在我的系统中,cc_tunsigned char,所以应该打印成%c或者%d

    【讨论】:

    猜你喜欢
    • 2018-02-22
    • 2013-03-10
    • 2012-09-27
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多