[英]How to check what the user set for erase/backspace in stty using c
在Unix中,每個平台的某些鍵的默認設置是不同的。 例如,Ubuntu中的erase = ^?
可能是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未宣布。 那么實際上我應該使用的正確選項或變量是什么?
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)了解更多詳情。
擦除字符的符號索引是VERASE
; c_cc[VERASE]
的類型是cc_t
,在我的系統中, cc_t
是unsigned char
,因此應該用%c
或%d
打印。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.