Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top