#include #include #include #define TERMINAL_FD 0 #define MAX_CHARS 50 #define LOWERCASE_W 119 int main() { // Declaring the variables we'll be using. struct termios old, new; char *input; // Grabbing terminal settings. tcgetattr(TERMINAL_FD, &old); new = old; // Getting memory from the heap for the input string. input = malloc(sizeof(char) * MAX_CHARS); /* * Setting erase key to w. I figured out how to do * this using the man page given here: * http://man7.org/linux/man-pages/man3/termios.3.html/ */ new.c_cc[VERASE] = LOWERCASE_W; tcsetattr(TERMINAL_FD, TCSANOW, &new); // Pressing the w key erases input! printf("Press the w key to erase: "); fgets(input, MAX_CHARS, stdin); printf("\nYou entered: %s", input); // Reverting settings. tcsetattr(TERMINAL_FD, TCSANOW, &old); // Freeing memory allocated. free(input); return 0; }