When I'm in a Linux bash shell, pressing the left and right arrow keys can be used to move the cursor on the command line, while the up and down arrow key can recall command history. But if I write a program that reads an input line using gets() as below, pressing those keys just produces the raw escape sequence. Is there a way to have the line edited, like in the shell, before it is returned by fgets()? Is there an alternative function?
while (fgets(buf, sizeof(buf), stdin))
I tried first calling noraw() and nocbreak(), but it does make a difference.