0

In Unix, the default setting for certain keys are different by each platform. For example, erase in Ubuntu might be erase = ^?. But then, for AIX, it might be totally different like example erase = ^H. How do I check the stty setting in C?

This is what I have tried to write

#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;
}

After compiling it using gcc. It says that ERASE undeclared. So what is actually the correct option or variable that I should use?

Mohd Fikrie
  • 197
  • 4
  • 21

1 Answers1

2

printf("The value for Erase is %s\n",term.c_cc[ERASE]); should be printf("The value for Erase is %d\n",term.c_cc[VERASE]);, see termios(3) for further details.

The symbolic index for Erase character is VERASE; the type of c_cc[VERASE] is cc_t, in my system, cc_t is unsigned char, so it should be printed with %c or %d.

Lee Duhem
  • 14,695
  • 3
  • 29
  • 47
  • Exactly. These are all well documented in the [`man 3 termios`](http://man7.org/linux/man-pages/man3/termios.3.html) man page. (That [link](http://man7.org/linux/man-pages/man3/termios.3.html) points to [the Linux man-pages project](https://www.kernel.org/doc/man-pages/), which is in my opinion one of the most reliable sources for details such as these.) – Nominal Animal Feb 20 '14 at 06:46